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,
);
static ThemeData light([ColorScheme? colorScheme]) => ThemeData(
static ThemeData buildTheme(Brightness brightness,
[ColorScheme? colorScheme]) =>
ThemeData(
visualDensity: VisualDensity.standard,
useMaterial3: true,
brightness: Brightness.light,
brightness: brightness,
colorSchemeSeed: AppConfig.colorSchemeSeed ??
colorScheme?.primary ??
AppConfig.chatColor,
@ -42,23 +44,16 @@ abstract class FluffyThemes {
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(),
},
),
dividerColor: Colors.blueGrey.shade50,
dividerColor: brightness == Brightness.light
? Colors.blueGrey.shade50
: Colors.blueGrey.shade900,
inputDecorationTheme: const InputDecorationTheme(
border: UnderlineInputBorder(borderSide: BorderSide(width: 1)),
filled: true,
),
appBarTheme: AppBarTheme(
surfaceTintColor: Colors.white,
surfaceTintColor:
brightness == Brightness.light ? Colors.white : Colors.black,
shadowColor: Colors.black.withAlpha(64),
),
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) {
return DynamicColorBuilder(
builder: (lightColorScheme, darkColorScheme) => AdaptiveTheme(
light: FluffyThemes.light(lightColorScheme),
dark: FluffyThemes.dark(darkColorScheme),
light: FluffyThemes.buildTheme(
Brightness.light,
lightColorScheme,
),
dark: FluffyThemes.buildTheme(
Brightness.dark,
lightColorScheme,
),
initial: AdaptiveThemeMode.system,
builder: (theme, darkTheme) => LayoutBuilder(
builder: (context, constraints) {

View File

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

View File

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

View File

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