diff --git a/app/lib/session_storage.dart b/app/lib/session_storage.dart index e93c08b8..38252a75 100644 --- a/app/lib/session_storage.dart +++ b/app/lib/session_storage.dart @@ -1,4 +1,5 @@ import 'package:clock/clock.dart'; +import 'package:flutter/material.dart'; /// Hold non-persisted global variables class SessionStorage { @@ -16,6 +17,8 @@ class SessionStorage { /// Whether the dynamic_color library is supported in this platform bool isSupportDynamicColor = false; + ColorScheme? lightDynamicColorScheme; + ColorScheme? darkDynamicColorScheme; DateTime lastSuspendTime = clock.now(); diff --git a/app/lib/theme.dart b/app/lib/theme.dart index 8a111c03..7cc17b39 100644 --- a/app/lib/theme.dart +++ b/app/lib/theme.dart @@ -4,6 +4,7 @@ import 'package:flex_seed_scheme/flex_seed_scheme.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:nc_photos/controller/pref_controller.dart'; +import 'package:nc_photos/session_storage.dart'; import 'package:nc_photos/theme/dimension.dart'; import 'package:np_ui/np_ui.dart'; @@ -116,12 +117,20 @@ ThemeData buildTheme(BuildContext context, Brightness brightness) { } ThemeData buildLightTheme(BuildContext context, [ColorScheme? dynamicScheme]) { - final colorScheme = _getColorScheme(context, dynamicScheme, Brightness.light); + final colorScheme = _getColorScheme( + context, + dynamicScheme ?? SessionStorage().lightDynamicColorScheme, + Brightness.light, + ); return _applyColorScheme(colorScheme); } ThemeData buildDarkTheme(BuildContext context, [ColorScheme? dynamicScheme]) { - final colorScheme = _getColorScheme(context, dynamicScheme, Brightness.dark); + final colorScheme = _getColorScheme( + context, + dynamicScheme ?? SessionStorage().darkDynamicColorScheme, + Brightness.dark, + ); if (context.read().isUseBlackInDarkTheme.value) { return _applyColorScheme(colorScheme.copyWith( background: Colors.black, diff --git a/app/lib/widget/my_app.dart b/app/lib/widget/my_app.dart index b352acfd..b81b6da5 100644 --- a/app/lib/widget/my_app.dart +++ b/app/lib/widget/my_app.dart @@ -137,9 +137,10 @@ class _WrappedAppState extends State<_WrappedApp> previous.secondarySeedColor != current.secondarySeedColor, builder: (context, state) => DynamicColorBuilder( builder: (lightDynamic, darkDynamic) { - if (lightDynamic != null) { - SessionStorage().isSupportDynamicColor = true; - } + SessionStorage() + ..lightDynamicColorScheme = lightDynamic + ..darkDynamicColorScheme = darkDynamic + ..isSupportDynamicColor = lightDynamic != null; final ThemeMode themeMode; if (state.isFollowSystemTheme) { themeMode = ThemeMode.system;