fix: ThemeMode not works under copied data

This commit is contained in:
lollipopkit
2023-03-21 15:36:35 +08:00
parent 7732ce5dbb
commit 9e3afe98a9
6 changed files with 45 additions and 33 deletions

View File

@@ -41,6 +41,8 @@ class MyApp extends StatelessWidget {
final radioTheme = RadioThemeData(
fillColor: materialColor,
);
final primarySwatch = primaryColor.materialColor;
return ValueListenableBuilder<int>(
valueListenable: _setting.themeMode.listenable(),
builder: (_, tMode, __) {
@@ -51,7 +53,7 @@ class MyApp extends StatelessWidget {
useMaterial3: false,
fontFamily: fontName,
primaryColor: primaryColor,
primarySwatch: primaryColor.materialColor,
primarySwatch: primarySwatch,
appBarTheme: appBarTheme,
floatingActionButtonTheme: fabTheme,
iconTheme: iconTheme,
@@ -60,6 +62,24 @@ class MyApp extends StatelessWidget {
inputDecorationTheme: inputDecorationTheme,
radioTheme: radioTheme,
);
final darkTheme = ThemeData(
useMaterial3: false,
fontFamily: fontName,
primaryColor: primaryColor,
primarySwatch: primarySwatch,
floatingActionButtonTheme: fabTheme,
iconTheme: iconTheme,
primaryIconTheme: iconTheme,
switchTheme: switchTheme,
inputDecorationTheme: inputDecorationTheme,
radioTheme: radioTheme,
brightness: Brightness.dark,
colorScheme: ColorScheme.fromSwatch(
primarySwatch: primaryColor.materialColor,
brightness: Brightness.dark,
accentColor: primaryColor,
),
);
return MaterialApp(
debugShowCheckedModeBanner: false,
@@ -68,13 +88,7 @@ class MyApp extends StatelessWidget {
title: BuildData.name,
themeMode: themeMode,
theme: theme,
darkTheme: theme.copyWith(
colorScheme: ColorScheme.fromSwatch(
primarySwatch: primaryColor.materialColor,
brightness: Brightness.dark,
accentColor: primaryColor,
),
),
darkTheme: darkTheme,
home: const MyHomePage(),
);
},