refactor: Simplify themes and remove dead code

This commit is contained in:
Christian Pauly 2022-08-19 08:32:08 +02:00
parent 033057270c
commit 9bc27edaba
5 changed files with 23 additions and 85 deletions

View File

@ -29,10 +29,12 @@ abstract class FluffyThemes {
subtitle2: fallbackTextStyle, subtitle2: fallbackTextStyle,
); );
static ThemeData light([ColorScheme? colorScheme]) => ThemeData( static ThemeData buildTheme(Brightness brightness,
[ColorScheme? colorScheme]) =>
ThemeData(
visualDensity: VisualDensity.standard, visualDensity: VisualDensity.standard,
useMaterial3: true, useMaterial3: true,
brightness: Brightness.light, brightness: brightness,
colorSchemeSeed: AppConfig.colorSchemeSeed ?? colorSchemeSeed: AppConfig.colorSchemeSeed ??
colorScheme?.primary ?? colorScheme?.primary ??
AppConfig.chatColor, AppConfig.chatColor,
@ -42,23 +44,16 @@ abstract class FluffyThemes {
snackBarTheme: const SnackBarThemeData( snackBarTheme: const SnackBarThemeData(
behavior: SnackBarBehavior.floating, behavior: SnackBarBehavior.floating,
), ),
pageTransitionsTheme: const PageTransitionsTheme( dividerColor: brightness == Brightness.light
builders: { ? Colors.blueGrey.shade50
TargetPlatform.fuchsia: ZoomPageTransitionsBuilder(), : Colors.blueGrey.shade900,
TargetPlatform.android: ZoomPageTransitionsBuilder(),
TargetPlatform.linux: CupertinoPageTransitionsBuilder(),
TargetPlatform.macOS: CupertinoPageTransitionsBuilder(),
TargetPlatform.windows: CupertinoPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
},
),
dividerColor: Colors.blueGrey.shade50,
inputDecorationTheme: const InputDecorationTheme( inputDecorationTheme: const InputDecorationTheme(
border: UnderlineInputBorder(borderSide: BorderSide(width: 1)), border: UnderlineInputBorder(borderSide: BorderSide(width: 1)),
filled: true, filled: true,
), ),
appBarTheme: AppBarTheme( appBarTheme: AppBarTheme(
surfaceTintColor: Colors.white, surfaceTintColor:
brightness == Brightness.light ? Colors.white : Colors.black,
shadowColor: Colors.black.withAlpha(64), shadowColor: Colors.black.withAlpha(64),
), ),
elevatedButtonTheme: ElevatedButtonThemeData( elevatedButtonTheme: ElevatedButtonThemeData(
@ -68,67 +63,4 @@ abstract class FluffyThemes {
), ),
), ),
); );
static ThemeData dark([ColorScheme? colorScheme]) => ThemeData(
visualDensity: VisualDensity.standard,
useMaterial3: true,
brightness: Brightness.dark,
colorSchemeSeed: AppConfig.colorSchemeSeed ??
colorScheme?.primary ??
AppConfig.chatColor,
textTheme: PlatformInfos.isDesktop
? Typography.material2018().white.merge(fallbackTextTheme)
: null,
snackBarTheme:
const SnackBarThemeData(behavior: SnackBarBehavior.floating),
pageTransitionsTheme: const PageTransitionsTheme(
builders: {
TargetPlatform.fuchsia: ZoomPageTransitionsBuilder(),
TargetPlatform.android: ZoomPageTransitionsBuilder(),
TargetPlatform.linux: CupertinoPageTransitionsBuilder(),
TargetPlatform.macOS: CupertinoPageTransitionsBuilder(),
TargetPlatform.windows: CupertinoPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
},
),
inputDecorationTheme: const InputDecorationTheme(
border: UnderlineInputBorder(borderSide: BorderSide(width: 1)),
filled: true,
),
dividerColor: Colors.blueGrey.shade900,
appBarTheme: AppBarTheme(
surfaceTintColor: Colors.black,
shadowColor: Colors.black.withAlpha(64),
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.all(16),
textStyle: const TextStyle(fontSize: 16),
),
),
);
static Color blackWhiteColor(BuildContext context) =>
Theme.of(context).brightness == Brightness.light
? Colors.white
: Colors.black;
static Color darken(Color color, [double amount = .1]) {
assert(amount >= 0 && amount <= 1);
final hsl = HSLColor.fromColor(color);
final hslDark = hsl.withLightness((hsl.lightness - amount).clamp(0.0, 1.0));
return hslDark.toColor();
}
static Color lighten(Color color, [double amount = .1]) {
assert(amount >= 0 && amount <= 1);
final hsl = HSLColor.fromColor(color);
final hslLight =
hsl.withLightness((hsl.lightness + amount).clamp(0.0, 1.0));
return hslLight.toColor();
}
} }

View File

@ -99,8 +99,14 @@ class FluffyChatAppState extends State<FluffyChatApp> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return DynamicColorBuilder( return DynamicColorBuilder(
builder: (lightColorScheme, darkColorScheme) => AdaptiveTheme( builder: (lightColorScheme, darkColorScheme) => AdaptiveTheme(
light: FluffyThemes.light(lightColorScheme), light: FluffyThemes.buildTheme(
dark: FluffyThemes.dark(darkColorScheme), Brightness.light,
lightColorScheme,
),
dark: FluffyThemes.buildTheme(
Brightness.dark,
lightColorScheme,
),
initial: AdaptiveThemeMode.system, initial: AdaptiveThemeMode.system,
builder: (theme, darkTheme) => LayoutBuilder( builder: (theme, darkTheme) => LayoutBuilder(
builder: (context, constraints) { builder: (context, constraints) {

View File

@ -44,8 +44,8 @@ class SettingsStyleController extends State<SettingsStyle> {
); );
AppConfig.colorSchemeSeed = color; AppConfig.colorSchemeSeed = color;
AdaptiveTheme.of(context).setTheme( AdaptiveTheme.of(context).setTheme(
light: FluffyThemes.light(), light: FluffyThemes.buildTheme(Brightness.light),
dark: FluffyThemes.dark(), dark: FluffyThemes.buildTheme(Brightness.dark),
); );
} }

View File

@ -25,8 +25,8 @@ class LockScreenState extends State<LockScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
theme: FluffyThemes.light(), theme: FluffyThemes.buildTheme(Brightness.light),
darkTheme: FluffyThemes.light(), darkTheme: FluffyThemes.buildTheme(Brightness.dark),
localizationsDelegates: L10n.localizationsDelegates, localizationsDelegates: L10n.localizationsDelegates,
supportedLocales: L10n.supportedLocales, supportedLocales: L10n.supportedLocales,
home: Builder( home: Builder(

View File

@ -479,8 +479,8 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
if (value != null && int.tryParse(value) != null) { if (value != null && int.tryParse(value) != null) {
AppConfig.colorSchemeSeed = Color(int.parse(value)); AppConfig.colorSchemeSeed = Color(int.parse(value));
AdaptiveTheme.of(context).setTheme( AdaptiveTheme.of(context).setTheme(
light: FluffyThemes.light(), light: FluffyThemes.buildTheme(Brightness.light),
dark: FluffyThemes.dark(), dark: FluffyThemes.buildTheme(Brightness.dark),
); );
} }
}); });