mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
支持主题切换
This commit is contained in:
@@ -15,6 +15,7 @@ import 'package:qinglong_app/module/others/scripts/script_edit_page.dart';
|
||||
import 'package:qinglong_app/module/others/scripts/script_page.dart';
|
||||
import 'package:qinglong_app/module/others/task_log/task_log_detail_page.dart';
|
||||
import 'package:qinglong_app/module/others/task_log/task_log_page.dart';
|
||||
import 'package:qinglong_app/module/others/theme_page.dart';
|
||||
import 'package:qinglong_app/module/others/update_password_page.dart';
|
||||
import 'package:qinglong_app/module/task/add_task_page.dart';
|
||||
import 'package:qinglong_app/module/task/task_bean.dart';
|
||||
@@ -39,6 +40,7 @@ class Routes {
|
||||
static const String routeDependency = "/Dependency";
|
||||
static const String routeUpdatePassword = "/updatePassword";
|
||||
static const String routeAbout = "/about";
|
||||
static const String routeTheme = "/theme";
|
||||
|
||||
static Route<dynamic>? generateRoute(RouteSettings settings) {
|
||||
switch (settings.name) {
|
||||
@@ -56,7 +58,8 @@ class Routes {
|
||||
return CupertinoPageRoute(builder: (context) => const AddTaskPage());
|
||||
}
|
||||
case routeAddDependency:
|
||||
return CupertinoPageRoute(builder: (context) => const AddDependencyPage());
|
||||
return CupertinoPageRoute(
|
||||
builder: (context) => const AddDependencyPage());
|
||||
case routeAddEnv:
|
||||
if (settings.arguments != null) {
|
||||
return CupertinoPageRoute(
|
||||
@@ -122,6 +125,10 @@ class Routes {
|
||||
return CupertinoPageRoute(
|
||||
builder: (context) => const AboutPage(),
|
||||
);
|
||||
case routeTheme:
|
||||
return CupertinoPageRoute(
|
||||
builder: (context) => const ThemePage(),
|
||||
);
|
||||
case routeScriptUpdate:
|
||||
return CupertinoPageRoute(
|
||||
builder: (context) => ScriptEditPage(
|
||||
|
||||
@@ -4,3 +4,4 @@ String spUserName = "username";
|
||||
String spPassWord = "password";
|
||||
String spTheme = "dart_mode";
|
||||
String spSecretLogined = "secret_logined";
|
||||
String spCustomColor = "customColor";
|
||||
|
||||
@@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:qinglong_app/base/sp_const.dart';
|
||||
import 'package:qinglong_app/base/userinfo_viewmodel.dart';
|
||||
import 'package:qinglong_app/main.dart';
|
||||
import 'package:qinglong_app/utils/codeeditor_theme.dart';
|
||||
import 'package:qinglong_app/utils/sp_utils.dart';
|
||||
|
||||
@@ -10,8 +12,6 @@ var themeProvider = ChangeNotifierProvider((ref) => ThemeViewModel());
|
||||
Color _primaryColor = const Color(0xFF299343);
|
||||
|
||||
class ThemeViewModel extends ChangeNotifier {
|
||||
late ThemeData darkTheme;
|
||||
late ThemeData lightTheme;
|
||||
late ThemeData currentTheme;
|
||||
|
||||
bool _isInDarkMode = false;
|
||||
@@ -20,8 +20,8 @@ class ThemeViewModel extends ChangeNotifier {
|
||||
ThemeColors themeColor = LightThemeColors();
|
||||
|
||||
ThemeViewModel() {
|
||||
darkTheme = getDartTheme();
|
||||
lightTheme = getLightTheme();
|
||||
_primaryColor = Color(getIt<UserInfoViewModel>().primaryColor);
|
||||
primaryColor = Color(getIt<UserInfoViewModel>().primaryColor);
|
||||
var brightness = SchedulerBinding.instance!.window.platformBrightness;
|
||||
_isInDarkMode = brightness == Brightness.dark;
|
||||
changeThemeReal(_isInDarkMode, false);
|
||||
@@ -35,10 +35,10 @@ class ThemeViewModel extends ChangeNotifier {
|
||||
_isInDarkMode = dark;
|
||||
SpUtil.putBool(spTheme, dark);
|
||||
if (!dark) {
|
||||
currentTheme = lightTheme;
|
||||
currentTheme = getLightTheme();
|
||||
themeColor = LightThemeColors();
|
||||
} else {
|
||||
currentTheme = darkTheme;
|
||||
currentTheme = getDartTheme();
|
||||
themeColor = DartThemeColors();
|
||||
}
|
||||
if (notify) {
|
||||
@@ -48,6 +48,13 @@ class ThemeViewModel extends ChangeNotifier {
|
||||
|
||||
get darkMode => _isInDarkMode;
|
||||
|
||||
void changePrimaryColor(Color color) {
|
||||
_primaryColor = color;
|
||||
primaryColor = color;
|
||||
getIt<UserInfoViewModel>().updateCustomColor(color.value);
|
||||
changeThemeReal(SpUtil.getBool(spTheme, defValue: false), true);
|
||||
}
|
||||
|
||||
void changeTheme() {
|
||||
changeThemeReal(!SpUtil.getBool(spTheme, defValue: false), true);
|
||||
}
|
||||
|
||||
@@ -8,11 +8,13 @@ class UserInfoViewModel {
|
||||
String? _userName;
|
||||
String? _passWord;
|
||||
bool _useSecertLogined = false;
|
||||
int _primaryColor = 0xFF299343;
|
||||
|
||||
UserInfoViewModel() {
|
||||
String userInfoJson = SpUtil.getString(spUserInfo);
|
||||
_userName = SpUtil.getString(spUserName);
|
||||
_passWord = SpUtil.getString(spPassWord);
|
||||
_primaryColor = SpUtil.getInt(spCustomColor, defValue: 0xFF299343);
|
||||
|
||||
_useSecertLogined = SpUtil.getBool(spSecretLogined, defValue: false);
|
||||
_host = SpUtil.getString(spHost, defValue: '');
|
||||
@@ -39,6 +41,11 @@ class UserInfoViewModel {
|
||||
SpUtil.putBool(spSecretLogined, _useSecertLogined);
|
||||
}
|
||||
|
||||
void updateCustomColor(int color) {
|
||||
_primaryColor = color;
|
||||
SpUtil.putInt(spCustomColor, color);
|
||||
}
|
||||
|
||||
void updateHost(String host) {
|
||||
_host = host;
|
||||
SpUtil.putString(spHost, host);
|
||||
@@ -54,6 +61,8 @@ class UserInfoViewModel {
|
||||
|
||||
bool get useSecretLogined => _useSecertLogined;
|
||||
|
||||
int get primaryColor => _primaryColor;
|
||||
|
||||
bool isLogined() {
|
||||
return token != null && token!.isNotEmpty;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user