diff --git a/lib/app.dart b/lib/app.dart index cc9e1902..076e1aa3 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -43,7 +43,7 @@ class _AppState extends ConsumerState with AfterLayoutMixin { @override Widget build(BuildContext context) { return DynamicColorBuilder( - builder: (lightDynamic, darkDynamic) { + builder: (lightDynamicColorScheme, darkDynamicColorScheme) { return ValueListenableBuilder( valueListenable: dynamicThemingNotifier, builder: (_, __, ___) { @@ -53,20 +53,12 @@ class _AppState extends ConsumerState with AfterLayoutMixin { return ValueListenableBuilder( valueListenable: themeModeNotifier, builder: (_, themeMode, ___) { - final useDynamicTheming = ThemeManager().useDynamicTheming; - return MaterialApp.router( title: 'Material Notes', - theme: useDynamicTheming - ? ThemeManager().getLightDynamicTheme(lightDynamic) - : ThemeManager().getLightCustomTheme, - darkTheme: useDynamicTheming - ? ThemeManager().getDarkDynamicTheme(darkDynamic) - : ThemeManager().getDarkCustomTheme, + theme: ThemeManager().getLightTheme(lightDynamicColorScheme), + darkTheme: ThemeManager().getDarkTheme(darkDynamicColorScheme), themeMode: themeMode, - localizationsDelegates: const [ - ...AppLocalizations.localizationsDelegates, - ], + localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, locale: LocaleManager().locale, routerConfig: router, diff --git a/lib/common/widgets/note_tile.dart b/lib/common/widgets/note_tile.dart index 4be4c5f9..701bfa29 100644 --- a/lib/common/widgets/note_tile.dart +++ b/lib/common/widgets/note_tile.dart @@ -83,9 +83,7 @@ class _NoteTileState extends ConsumerState { onTap: _openOrSelect, onLongPress: widget.searchView ? null : _enterSelectionMode, child: Container( - // TODO: change when dynamic_color is updated (cf. https://github.com/material-foundation/flutter-packages/issues/574 and https://github.com/material-foundation/flutter-packages/issues/582) - color: - widget.note.selected ? Theme.of(context).colorScheme.surfaceVariant : null, // ignore: deprecated_member_use + color: widget.note.selected ? Theme.of(context).colorScheme.secondaryContainer : null, child: Padding( padding: Paddings.padding16.horizontal.add(Paddings.padding16.vertical), child: Row( diff --git a/lib/pages/editor/editor_page.dart b/lib/pages/editor/editor_page.dart index f9a25174..89439f56 100644 --- a/lib/pages/editor/editor_page.dart +++ b/lib/pages/editor/editor_page.dart @@ -131,8 +131,7 @@ class _EditorState extends ConsumerState { builder: (_, hasFocus, ___) { return showToolbar && hasFocus && KeyboardVisibilityProvider.isKeyboardVisible(context) ? ColoredBox( - // TODO: change when dynamic_color is updated (cf. https://github.com/material-foundation/flutter-packages/issues/574 and https://github.com/material-foundation/flutter-packages/issues/582) - color: Theme.of(context).colorScheme.surfaceVariant, // ignore: deprecated_member_use + color: Theme.of(context).colorScheme.secondaryContainer, child: EditorToolbar(fleatherController!), ) : Container(); diff --git a/lib/utils/theme_manager.dart b/lib/utils/theme_manager.dart index 751bcfb0..876abbe6 100644 --- a/lib/utils/theme_manager.dart +++ b/lib/utils/theme_manager.dart @@ -4,8 +4,6 @@ import 'package:localmaterialnotes/utils/constants/constants.dart'; import 'package:localmaterialnotes/utils/preferences/preference_key.dart'; import 'package:localmaterialnotes/utils/preferences/preferences_manager.dart'; -const _customPrimaryColor = Color(0xFF2278e9); - class ThemeManager { static final ThemeManager _singleton = ThemeManager._internal(); @@ -15,6 +13,8 @@ class ThemeManager { ThemeManager._internal(); + final _customPrimaryColor = const Color(0xFF2278e9); + late final bool isDynamicThemingAvailable; Future init() async { @@ -22,20 +22,6 @@ class ThemeManager { await DynamicColorPlugin.getCorePalette() != null || await DynamicColorPlugin.getAccentColor() != null; } - ColorScheme get _customLightColorScheme { - return ColorScheme.fromSeed( - seedColor: _customPrimaryColor, - ); - } - - ColorScheme get _customDarkColorScheme { - return ColorScheme.fromSeed( - brightness: Brightness.dark, - seedColor: _customPrimaryColor, - surface: useBlackTheming ? Colors.black : null, - ); - } - bool get useDynamicTheming { return PreferenceKey.dynamicTheming.getPreferenceOrDefault(); } @@ -78,6 +64,49 @@ class ThemeManager { return localizations.settings_theme_system; } + ThemeData getLightTheme(ColorScheme? lightDynamicColorScheme) { + final colorScheme = useDynamicTheming && lightDynamicColorScheme != null + ? lightDynamicColorScheme + : ColorScheme.fromSeed( + seedColor: _customPrimaryColor, + ); + + return ThemeData( + useMaterial3: true, + colorScheme: colorScheme, + ); + } + + ThemeData getDarkTheme(ColorScheme? darkDynamicColorScheme) { + final ColorScheme colorScheme; + + if (useDynamicTheming && darkDynamicColorScheme != null) { + colorScheme = useBlackTheming + ? darkDynamicColorScheme.copyWith( + // TODO: check if this is still needed to make the background of the pages black + background: Colors.black, // ignore: deprecated_member_use + surface: Colors.black, + ) + : darkDynamicColorScheme; + } else { + colorScheme = useBlackTheming + ? ColorScheme.fromSeed( + brightness: Brightness.dark, + seedColor: _customPrimaryColor, + surface: Colors.black, + ) + : ColorScheme.fromSeed( + brightness: Brightness.dark, + seedColor: _customPrimaryColor, + ); + } + + return ThemeData( + useMaterial3: true, + colorScheme: colorScheme, + ); + } + void setThemeMode(ThemeMode? themeMode) { if (themeMode == null) { return; @@ -96,37 +125,4 @@ class ThemeManager { themeModeNotifier.value = themeMode; } - - ThemeData getLightDynamicTheme([ColorScheme? lightDynamicColorScheme]) { - return ThemeData( - useMaterial3: true, - colorScheme: lightDynamicColorScheme != null ? lightDynamicColorScheme.harmonized() : _customLightColorScheme, - ); - } - - ThemeData getDarkDynamicTheme([ColorScheme? darkDynamicColorScheme]) { - return ThemeData( - useMaterial3: true, - colorScheme: darkDynamicColorScheme?.copyWith( - // TODO: remove when dynamic_color is updated (cf. https://github.com/material-foundation/flutter-packages/issues/574 and https://github.com/material-foundation/flutter-packages/issues/582) - background: useBlackTheming ? Colors.black : null, // ignore: deprecated_member_use - surface: useBlackTheming ? Colors.black : null, - ) ?? - _customDarkColorScheme, - ); - } - - ThemeData get getLightCustomTheme { - return ThemeData( - useMaterial3: true, - colorScheme: _customLightColorScheme, - ); - } - - ThemeData get getDarkCustomTheme { - return ThemeData( - useMaterial3: true, - colorScheme: _customDarkColorScheme, - ); - } }