From b8b195b66374bfd624dfca852e420a9b500e7c4d Mon Sep 17 00:00:00 2001 From: jyuesong <425698907@qq.com> Date: Fri, 21 Jan 2022 17:30:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=BB=E9=A2=98=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/base/theme.dart | 281 +++++++++--------- lib/module/env/env_detail_page.dart | 2 +- lib/module/env/env_page.dart | 6 +- lib/module/login/login_page.dart | 6 +- lib/module/others/about_page.dart | 6 +- .../others/dependencies/dependency_page.dart | 4 +- .../others/login_log/login_log_page.dart | 2 +- lib/module/others/other_page.dart | 2 +- .../others/scripts/script_detail_page.dart | 2 +- .../task/task_detail/task_detail_page.dart | 2 +- lib/module/task/task_page.dart | 2 +- 11 files changed, 162 insertions(+), 153 deletions(-) diff --git a/lib/base/theme.dart b/lib/base/theme.dart index 7d78418..13d0688 100644 --- a/lib/base/theme.dart +++ b/lib/base/theme.dart @@ -7,17 +7,21 @@ import 'package:qinglong_app/utils/codeeditor_theme.dart'; import 'package:qinglong_app/utils/sp_utils.dart'; var themeProvider = ChangeNotifierProvider((ref) => ThemeViewModel()); -const Color _primaryColor = Color(0xFF299343); - -get primaryColor => _primaryColor; +Color _primaryColor = const Color(0xFF299343); class ThemeViewModel extends ChangeNotifier { - ThemeData currentTheme = lightTheme; + late ThemeData darkTheme; + late ThemeData lightTheme; + late ThemeData currentTheme; + bool _isInDarkMode = false; + Color primaryColor = const Color(0xFF299343); ThemeColors themeColor = LightThemeColors(); ThemeViewModel() { + darkTheme = getDartTheme(); + lightTheme = getLightTheme(); var brightness = SchedulerBinding.instance!.window.platformBrightness; _isInDarkMode = brightness == Brightness.dark; changeThemeReal(_isInDarkMode, false); @@ -47,146 +51,151 @@ class ThemeViewModel extends ChangeNotifier { void changeTheme() { changeThemeReal(!SpUtil.getBool(spTheme, defValue: false), true); } -} -ThemeData darkTheme = ThemeData.dark().copyWith( - brightness: Brightness.dark, - primaryColor: const Color(0xffffffff), - scaffoldBackgroundColor: Colors.black, - appBarTheme: const AppBarTheme( - backgroundColor: Colors.black, - titleTextStyle: TextStyle( - color: Colors.white, - fontSize: 18, - ), - ), - inputDecorationTheme: const InputDecorationTheme( - labelStyle: TextStyle(color: _primaryColor), - focusedBorder: UnderlineInputBorder( - borderSide: BorderSide( + ThemeData getLightTheme() { + return ThemeData.light().copyWith( + brightness: Brightness.light, + primaryColor: _primaryColor, + colorScheme: ColorScheme.light( + secondary: _primaryColor, + primary: _primaryColor, + ), + scaffoldBackgroundColor: const Color(0xfff5f5f5), + inputDecorationTheme: InputDecorationTheme( + labelStyle: TextStyle(color: _primaryColor), + focusedBorder: UnderlineInputBorder( + borderSide: BorderSide( + color: _primaryColor, + ), + ), + border: const UnderlineInputBorder( + borderSide: BorderSide( + color: Color(0xff999999), + ), + ), + enabledBorder: const UnderlineInputBorder( + borderSide: BorderSide( + color: Color(0xff999999), + ), + ), + ), + appBarTheme: AppBarTheme( + backgroundColor: _primaryColor, + titleTextStyle: const TextStyle( + color: Colors.white, + fontSize: 18, + ), + ), + bottomNavigationBarTheme: BottomNavigationBarThemeData( + selectedItemColor: _primaryColor, + ), + buttonTheme: ButtonThemeData( + buttonColor: _primaryColor, + ), + progressIndicatorTheme: ProgressIndicatorThemeData( color: _primaryColor, ), - ), - border: UnderlineInputBorder( - borderSide: BorderSide( - color: Color(0xff999999), + tabBarTheme: TabBarTheme( + labelStyle: const TextStyle( + fontSize: 14, + ), + unselectedLabelStyle: const TextStyle( + fontSize: 14, + ), + labelColor: _primaryColor, + unselectedLabelColor: const Color(0xff999999), + indicator: UnderlineTabIndicator( + borderSide: BorderSide(color: _primaryColor), + ), ), - ), - enabledBorder: UnderlineInputBorder( - borderSide: BorderSide( - color: Color(0xff999999), + toggleableActiveColor: _primaryColor, + checkboxTheme: CheckboxThemeData( + checkColor: MaterialStateProperty.resolveWith( + (Set states) { + if (states.contains(MaterialState.disabled)) { + return Colors.transparent; + } + if (states.contains(MaterialState.selected)) { + return Colors.white; + } + return Colors.black; + }, + ), ), - ), - ), - tabBarTheme: const TabBarTheme( - labelStyle: TextStyle( - fontSize: 14, - ), - unselectedLabelStyle: TextStyle( - fontSize: 14, - ), - labelColor: Color(0xffffffff), - unselectedLabelColor: Color(0xff999999), - ), - colorScheme: const ColorScheme.light( - secondary: _primaryColor, - primary: _primaryColor, - ), - toggleableActiveColor: _primaryColor, - checkboxTheme: CheckboxThemeData( - checkColor: MaterialStateProperty.resolveWith( - (Set states) { - if (states.contains(MaterialState.disabled)) { - return Colors.transparent; - } - if (states.contains(MaterialState.selected)) { - return Colors.white; - } - return Colors.white; - }, - ), - ), - cupertinoOverrideTheme: const NoDefaultCupertinoThemeData( - brightness: Brightness.dark, - primaryColor: Color(0xffffffff), - scaffoldBackgroundColor: Colors.black, - ), -); -ThemeData lightTheme = ThemeData.light().copyWith( - brightness: Brightness.light, - primaryColor: _primaryColor, - colorScheme: const ColorScheme.light( - secondary: _primaryColor, - primary: _primaryColor, - ), - scaffoldBackgroundColor: const Color(0xfff5f5f5), - inputDecorationTheme: const InputDecorationTheme( - labelStyle: TextStyle(color: _primaryColor), - focusedBorder: UnderlineInputBorder( - borderSide: BorderSide( - color: _primaryColor, + cupertinoOverrideTheme: NoDefaultCupertinoThemeData( + brightness: Brightness.light, + primaryColor: _primaryColor, + scaffoldBackgroundColor: const Color(0xfff5f5f5), ), - ), - border: UnderlineInputBorder( - borderSide: BorderSide( - color: Color(0xff999999), + ); + } + + ThemeData getDartTheme() { + return ThemeData.dark().copyWith( + brightness: Brightness.dark, + primaryColor: const Color(0xffffffff), + scaffoldBackgroundColor: Colors.black, + appBarTheme: const AppBarTheme( + backgroundColor: Colors.black, + titleTextStyle: TextStyle( + color: Colors.white, + fontSize: 18, + ), ), - ), - enabledBorder: UnderlineInputBorder( - borderSide: BorderSide( - color: Color(0xff999999), + inputDecorationTheme: InputDecorationTheme( + labelStyle: TextStyle(color: _primaryColor), + focusedBorder: UnderlineInputBorder( + borderSide: BorderSide( + color: _primaryColor, + ), + ), + border: const UnderlineInputBorder( + borderSide: BorderSide( + color: Color(0xff999999), + ), + ), + enabledBorder: const UnderlineInputBorder( + borderSide: BorderSide( + color: Color(0xff999999), + ), + ), ), - ), - ), - appBarTheme: const AppBarTheme( - backgroundColor: _primaryColor, - titleTextStyle: TextStyle( - color: Colors.white, - fontSize: 18, - ), - ), - bottomNavigationBarTheme: const BottomNavigationBarThemeData( - selectedItemColor: _primaryColor, - ), - buttonTheme: const ButtonThemeData( - buttonColor: _primaryColor, - ), - progressIndicatorTheme: const ProgressIndicatorThemeData( - color: _primaryColor, - ), - tabBarTheme: const TabBarTheme( - labelStyle: TextStyle( - fontSize: 14, - ), - unselectedLabelStyle: TextStyle( - fontSize: 14, - ), - labelColor: _primaryColor, - unselectedLabelColor: Color(0xff999999), - indicator: UnderlineTabIndicator( - borderSide: BorderSide(color: _primaryColor), - ), - ), - toggleableActiveColor: _primaryColor, - checkboxTheme: CheckboxThemeData( - checkColor: MaterialStateProperty.resolveWith( - (Set states) { - if (states.contains(MaterialState.disabled)) { - return Colors.transparent; - } - if (states.contains(MaterialState.selected)) { - return Colors.white; - } - return Colors.black; - }, - ), - ), - cupertinoOverrideTheme: const NoDefaultCupertinoThemeData( - brightness: Brightness.light, - primaryColor: _primaryColor, - scaffoldBackgroundColor: Color(0xfff5f5f5), - ), -); + tabBarTheme: const TabBarTheme( + labelStyle: TextStyle( + fontSize: 14, + ), + unselectedLabelStyle: TextStyle( + fontSize: 14, + ), + labelColor: Color(0xffffffff), + unselectedLabelColor: Color(0xff999999), + ), + colorScheme: ColorScheme.light( + secondary: _primaryColor, + primary: _primaryColor, + ), + toggleableActiveColor: _primaryColor, + checkboxTheme: CheckboxThemeData( + checkColor: MaterialStateProperty.resolveWith( + (Set states) { + if (states.contains(MaterialState.disabled)) { + return Colors.transparent; + } + if (states.contains(MaterialState.selected)) { + return Colors.white; + } + return Colors.white; + }, + ), + ), + cupertinoOverrideTheme: const NoDefaultCupertinoThemeData( + brightness: Brightness.dark, + primaryColor: Color(0xffffffff), + scaffoldBackgroundColor: Colors.black, + ), + ); + } +} abstract class ThemeColors { Color settingBgColor(); diff --git a/lib/module/env/env_detail_page.dart b/lib/module/env/env_detail_page.dart index fdc3540..913e7db 100644 --- a/lib/module/env/env_detail_page.dart +++ b/lib/module/env/env_detail_page.dart @@ -249,7 +249,7 @@ class _TaskDetailPageState extends ConsumerState { child: Text( "确定", style: TextStyle( - color: primaryColor, + color: ref.watch(themeProvider).primaryColor, ), ), onPressed: () async { diff --git a/lib/module/env/env_page.dart b/lib/module/env/env_page.dart index bb61003..c9f22b3 100644 --- a/lib/module/env/env_page.dart +++ b/lib/module/env/env_page.dart @@ -238,11 +238,11 @@ class EnvItemCell extends StatelessWidget { ), decoration: BoxDecoration( borderRadius: BorderRadius.circular(5), - border: Border.all(color: primaryColor, width: 1), + border: Border.all(color: ref.watch(themeProvider).primaryColor, width: 1), ), child: Text( "$index", - style: TextStyle(color: primaryColor, fontSize: 12), + style: TextStyle(color: ref.watch(themeProvider).primaryColor, fontSize: 12), ), ), const SizedBox( @@ -332,7 +332,7 @@ class EnvItemCell extends StatelessWidget { child: Text( "确定", style: TextStyle( - color: primaryColor, + color: ref.watch(themeProvider).primaryColor, ), ), onPressed: () { diff --git a/lib/module/login/login_page.dart b/lib/module/login/login_page.dart index b9c12bf..e99d395 100644 --- a/lib/module/login/login_page.dart +++ b/lib/module/login/login_page.dart @@ -115,7 +115,7 @@ class _LoginPageState extends ConsumerState { if (debugBtnIsShow()) { dismissDebugBtn(); } else { - showDebugBtn(context, btnColor: primaryColor); + showDebugBtn(context, btnColor: ref.watch(themeProvider).primaryColor); } WidgetsBinding.instance?.endOfFrame; }, @@ -327,7 +327,7 @@ class _LoginPageState extends ConsumerState { padding: const EdgeInsets.symmetric( vertical: 5, ), - color: canClickLoginBtn() ? primaryColor : primaryColor.withOpacity(0.4), + color: canClickLoginBtn() ? ref.watch(themeProvider).primaryColor : ref.watch(themeProvider).primaryColor.withOpacity(0.4), child: isLoading ? const CupertinoActivityIndicator() : const Text( @@ -476,7 +476,7 @@ class _LoginPageState extends ConsumerState { child: Text( "确定", style: TextStyle( - color: primaryColor, + color: ref.watch(themeProvider).primaryColor, ), ), onPressed: () async { diff --git a/lib/module/others/about_page.dart b/lib/module/others/about_page.dart index 083fe9c..ba2a206 100644 --- a/lib/module/others/about_page.dart +++ b/lib/module/others/about_page.dart @@ -91,7 +91,7 @@ class _AboutPageState extends ConsumerState { child: Text( "Telegram频道", style: TextStyle( - color: primaryColor, + color: ref.watch(themeProvider).primaryColor, fontSize: 16, ), ), @@ -107,7 +107,7 @@ class _AboutPageState extends ConsumerState { child: Text( "版本更新", style: TextStyle( - color: primaryColor, + color: ref.watch(themeProvider).primaryColor, fontSize: 16, ), ), @@ -122,7 +122,7 @@ class _AboutPageState extends ConsumerState { child: Text( "项目地址", style: TextStyle( - color: primaryColor, + color: ref.watch(themeProvider).primaryColor, fontSize: 16, ), ), diff --git a/lib/module/others/dependencies/dependency_page.dart b/lib/module/others/dependencies/dependency_page.dart index 594e9a7..aad98b5 100644 --- a/lib/module/others/dependencies/dependency_page.dart +++ b/lib/module/others/dependencies/dependency_page.dart @@ -231,7 +231,7 @@ class DependencyCell extends ConsumerWidget { bean.status == 1 ? Icon( CupertinoIcons.checkmark_circle, - color: primaryColor, + color: ref.watch(themeProvider).primaryColor, size: 16, ) : (bean.status == 2 @@ -348,7 +348,7 @@ class DependencyCell extends ConsumerWidget { child: Text( "确定", style: TextStyle( - color: primaryColor, + color: ref.watch(themeProvider).primaryColor, ), ), onPressed: () { diff --git a/lib/module/others/login_log/login_log_page.dart b/lib/module/others/login_log/login_log_page.dart index 7ceb496..8c985a7 100644 --- a/lib/module/others/login_log/login_log_page.dart +++ b/lib/module/others/login_log/login_log_page.dart @@ -86,7 +86,7 @@ class _LoginLogPageState extends ConsumerState with LazyLoadState< trailing: item.status == 0 ? Icon( CupertinoIcons.checkmark_circle, - color: primaryColor, + color: ref.watch(themeProvider).primaryColor, size: 16, ) : const Icon( diff --git a/lib/module/others/other_page.dart b/lib/module/others/other_page.dart index 15c469c..5386f3b 100644 --- a/lib/module/others/other_page.dart +++ b/lib/module/others/other_page.dart @@ -357,7 +357,7 @@ class _OtherPageState extends ConsumerState { child: Text( "确定", style: TextStyle( - color: primaryColor, + color: ref.watch(themeProvider).primaryColor, ), ), onPressed: () { diff --git a/lib/module/others/scripts/script_detail_page.dart b/lib/module/others/scripts/script_detail_page.dart index 2a1c06c..3460f6c 100644 --- a/lib/module/others/scripts/script_detail_page.dart +++ b/lib/module/others/scripts/script_detail_page.dart @@ -98,7 +98,7 @@ class _ScriptDetailPageState extends ConsumerState with LazyLo child: Text( "确定", style: TextStyle( - color: primaryColor, + color: ref.watch(themeProvider).primaryColor, ), ), onPressed: () async { diff --git a/lib/module/task/task_detail/task_detail_page.dart b/lib/module/task/task_detail/task_detail_page.dart index bf27596..16df237 100644 --- a/lib/module/task/task_detail/task_detail_page.dart +++ b/lib/module/task/task_detail/task_detail_page.dart @@ -385,7 +385,7 @@ class _TaskDetailPageState extends ConsumerState { child: Text( "确定", style: TextStyle( - color: primaryColor, + color: ref.watch(themeProvider).primaryColor, ), ), onPressed: () async { diff --git a/lib/module/task/task_page.dart b/lib/module/task/task_page.dart index 13776fa..870ed49 100644 --- a/lib/module/task/task_page.dart +++ b/lib/module/task/task_page.dart @@ -447,7 +447,7 @@ class TaskItemCell extends StatelessWidget { child: Text( "确定", style: TextStyle( - color: primaryColor, + color: ref.watch(themeProvider).primaryColor, ), ), onPressed: () {