diff --git a/lib/app.dart b/lib/app.dart index 87c1ba48..8a22b67c 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -19,69 +19,63 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { setTransparentNavigationBar(context); final fontName = getFileName(_setting.fontPath.fetch()); + primaryColor = Color(_setting.primaryColor.fetch()!); + + final textStyle = TextStyle(color: primaryColor); + final materialColor = primaryColor.materialStateColor; + final materialColorAlpha = primaryColor.withOpacity(0.7).materialStateColor; + final fabTheme = + FloatingActionButtonThemeData(backgroundColor: primaryColor); + final switchTheme = SwitchThemeData( + thumbColor: materialColor, + trackColor: materialColorAlpha, + ); + final appBarTheme = AppBarTheme(backgroundColor: primaryColor); + final iconTheme = IconThemeData(color: primaryColor); + final inputDecorationTheme = InputDecorationTheme( + labelStyle: textStyle, + focusedBorder: UnderlineInputBorder( + borderSide: BorderSide(color: primaryColor), + ), + ); + final radioTheme = RadioThemeData( + fillColor: materialColor, + ); return ValueListenableBuilder( - valueListenable: _setting.primaryColor.listenable(), - builder: (_, colorValue, __) { - primaryColor = Color(colorValue); + valueListenable: _setting.themeMode.listenable(), + builder: (_, tMode, __) { + final ok = tMode >= 0 && tMode <= ThemeMode.values.length - 1; + final themeMode = ok ? ThemeMode.values[tMode] : ThemeMode.system; - final textStyle = TextStyle(color: primaryColor); - final materialColor = primaryColor.materialStateColor; - final materialColorAlpha = - primaryColor.withOpacity(0.7).materialStateColor; - final fabTheme = - FloatingActionButtonThemeData(backgroundColor: primaryColor); - final switchTheme = SwitchThemeData( - thumbColor: materialColor, - trackColor: materialColorAlpha, + final theme = ThemeData( + useMaterial3: false, + fontFamily: fontName, + primaryColor: primaryColor, + primarySwatch: primaryColor.materialColor, + appBarTheme: appBarTheme, + floatingActionButtonTheme: fabTheme, + iconTheme: iconTheme, + primaryIconTheme: iconTheme, + switchTheme: switchTheme, + inputDecorationTheme: inputDecorationTheme, + radioTheme: radioTheme, ); - final appBarTheme = AppBarTheme(backgroundColor: primaryColor); - final iconTheme = IconThemeData(color: primaryColor); - final inputDecorationTheme = InputDecorationTheme( - labelStyle: textStyle, - focusedBorder: UnderlineInputBorder( - borderSide: BorderSide(color: primaryColor), - ), - ); - final radioTheme = RadioThemeData( - fillColor: materialColor, - ); - return ValueListenableBuilder( - valueListenable: _setting.themeMode.listenable(), - builder: (_, tMode, __) { - final ok = tMode >= 0 && tMode <= ThemeMode.values.length - 1; - final themeMode = ok ? ThemeMode.values[tMode] : ThemeMode.system; - final theme = ThemeData( - useMaterial3: false, - fontFamily: fontName, - primaryColor: primaryColor, + return MaterialApp( + debugShowCheckedModeBanner: false, + localizationsDelegates: S.localizationsDelegates, + supportedLocales: S.supportedLocales, + title: BuildData.name, + themeMode: themeMode, + theme: theme, + darkTheme: theme.copyWith( + colorScheme: ColorScheme.fromSwatch( primarySwatch: primaryColor.materialColor, - appBarTheme: appBarTheme, - floatingActionButtonTheme: fabTheme, - iconTheme: iconTheme, - primaryIconTheme: iconTheme, - switchTheme: switchTheme, - inputDecorationTheme: inputDecorationTheme, - radioTheme: radioTheme, - ); - - return MaterialApp( - debugShowCheckedModeBanner: false, - localizationsDelegates: S.localizationsDelegates, - supportedLocales: S.supportedLocales, - title: BuildData.name, - themeMode: themeMode, - theme: theme, - darkTheme: theme.copyWith( - colorScheme: ColorScheme.fromSwatch( - primarySwatch: primaryColor.materialColor, - brightness: Brightness.dark, - accentColor: primaryColor, - ), - ), - home: const MyHomePage(), - ); - }, + brightness: Brightness.dark, + accentColor: primaryColor, + ), + ), + home: const MyHomePage(), ); }, ); diff --git a/lib/data/store/setting.dart b/lib/data/store/setting.dart index 69b8f9fb..29e3750e 100644 --- a/lib/data/store/setting.dart +++ b/lib/data/store/setting.dart @@ -34,5 +34,5 @@ class SettingStore extends PersistentStore { StoreProperty get themeMode => property('themeMode', defaultValue: 0); /// Font file path - StoreProperty get fontPath => property('fontPath2'); + StoreProperty get fontPath => property('fontPath'); } diff --git a/lib/view/page/home.dart b/lib/view/page/home.dart index 368c0da5..061354cb 100644 --- a/lib/view/page/home.dart +++ b/lib/view/page/home.dart @@ -68,7 +68,6 @@ class _MyHomePageState extends State void dispose() { super.dispose(); WidgetsBinding.instance.removeObserver(this); - _serverProvider.closeServer(); } @override diff --git a/lib/view/page/server/tab.dart b/lib/view/page/server/tab.dart index 53853589..7a5dc83d 100644 --- a/lib/view/page/server/tab.dart +++ b/lib/view/page/server/tab.dart @@ -445,8 +445,7 @@ class _ServerPageState extends State await GetIt.I.allReady(); if (_serverProvider.servers.isEmpty) { await _serverProvider.loadLocalData(); - await _serverProvider.refreshData(); - _serverProvider.startAutoRefresh(); } + _serverProvider.startAutoRefresh(); } } diff --git a/lib/view/page/setting.dart b/lib/view/page/setting.dart index 92dfba63..70208e9a 100644 --- a/lib/view/page/setting.dart +++ b/lib/view/page/setting.dart @@ -241,7 +241,7 @@ class _SettingPageState extends State { icon: const Icon(Icons.save), onPressed: (() { _setting.primaryColor.put(_selectedColorValue); - setState(() {}); + _showRestartSnackbar(); }), ); } @@ -459,18 +459,13 @@ class _SettingPageState extends State { mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ TextButton( - onPressed: () async => pickFontFile(), + onPressed: () async => _pickFontFile(), child: Text(_s.pickFile), ), TextButton( onPressed: () => setState(() { _setting.fontPath.delete(); - showSnackBarWithAction( - context, - '${_s.success}\n${_s.needRestart}', - _s.restart, - () => rebuildAll(context), - ); + _showRestartSnackbar(); }), child: Text(_s.clear), ) @@ -480,7 +475,7 @@ class _SettingPageState extends State { ); } - Future pickFontFile() async { + Future _pickFontFile() async { final path = await pickOneFile(); if (path != null) { final fontDir_ = await fontDir; @@ -489,14 +484,18 @@ class _SettingPageState extends State { await fontFile.copy(newPath); _setting.fontPath.put(newPath); setState(() {}); - showSnackBarWithAction( - context, - '${_s.success}\n${_s.needRestart}', - _s.restart, - () => rebuildAll(context), - ); + _showRestartSnackbar(); return; } showSnackBar(context, Text(_s.failed)); } + + void _showRestartSnackbar() { + showSnackBarWithAction( + context, + '${_s.success}\n${_s.needRestart}', + _s.restart, + () => rebuildAll(context), + ); + } }