add setting

This commit is contained in:
jyuesong
2022-01-17 17:13:53 +08:00
parent 352d4e162c
commit afd2b30616
4 changed files with 151 additions and 57 deletions

View File

@@ -1,2 +1,3 @@
String sp_UserINfo = "userinfo";
String sp_Host = "host";
String sp_Theme = "dart_mode";

View File

@@ -1,7 +1,9 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:qinglong_app/base/sp_const.dart';
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);
@@ -11,16 +13,32 @@ class ThemeViewModel extends ChangeNotifier {
ThemeColors themeColor = LightThemeColors();
void changeTheme() {
if (currentTheme == darkTheme) {
ThemeViewModel() {
bool dartMode = SpUtil.getBool(sp_Theme, defValue: false);
changeThemeReal(dartMode, false);
}
bool isInDartMode() {
return SpUtil.getBool(sp_Theme, defValue: false);
}
void changeThemeReal(bool dark, [bool notify = true]) {
SpUtil.putBool(sp_Theme, dark);
if (!dark) {
currentTheme = lightTheme;
themeColor = LightThemeColors();
} else {
currentTheme = darkTheme;
themeColor = DartThemeColors();
}
if (notify) {
notifyListeners();
}
}
void changeTheme() {
changeThemeReal(!SpUtil.getBool(sp_Theme, defValue: false), true);
}
}
ThemeData darkTheme = ThemeData.dark().copyWith(
@@ -57,7 +75,7 @@ ThemeData lightTheme = ThemeData.light().copyWith(
secondary: _primaryColor,
primary: _primaryColor,
),
scaffoldBackgroundColor: Colors.white,
scaffoldBackgroundColor: const Color(0xfff5f5f5),
inputDecorationTheme: const InputDecorationTheme(
labelStyle: TextStyle(color: _primaryColor),
focusedBorder: UnderlineInputBorder(
@@ -94,12 +112,12 @@ ThemeData lightTheme = ThemeData.light().copyWith(
);
abstract class ThemeColors {
Color settingBgColor();
Color taskTitleColor();
Color descColor();
Color backGround();
Color pinColor();
Map<String, TextStyle> codeEditorTheme();
@@ -111,11 +129,6 @@ class LightThemeColors extends ThemeColors {
return Color(0xff333333);
}
@override
Color searchBarBg() {
return const Color(0xffF7F7F7);
}
@override
Color pinColor() {
return const Color(0xffF7F7F7);
@@ -132,8 +145,8 @@ class LightThemeColors extends ThemeColors {
}
@override
Color backGround() {
return Color(0xffF5F5F5);
Color settingBgColor() {
return Colors.white;
}
}
@@ -143,11 +156,6 @@ class DartThemeColors extends ThemeColors {
return Colors.white;
}
@override
Color searchBarBg() {
return const Color(0xff2E312E);
}
@override
Color pinColor() {
return Colors.black12;
@@ -164,7 +172,7 @@ class DartThemeColors extends ThemeColors {
}
@override
Color backGround() {
Color settingBgColor() {
return Colors.black;
}
}

View File

@@ -70,25 +70,13 @@ class _HomePageState extends ConsumerState<HomePage> {
));
}
actions.add(
Consumer(builder: (context, ref, child) {
return InkWell(
onTap: () {
ref.read(themeProvider).changeTheme();
},
child: const Center(child: Text("改变主题")),
);
}),
);
return Scaffold(
appBar: QlAppBar(
canBack: false,
title: _title,
actions: actions,
),
body: ColoredBox(
color: ref.watch(themeProvider).themeColor.backGround(),
child: IndexedStack(
body: IndexedStack(
index: _index,
children: [
const Positioned.fill(
@@ -107,7 +95,6 @@ class _HomePageState extends ConsumerState<HomePage> {
),
],
),
),
bottomNavigationBar: BottomNavigationBar(
items: titles
.map(

View File

@@ -21,10 +21,13 @@ class _OtherPageState extends ConsumerState<OtherPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.symmetric(horizontal: 15,vertical: 15,),
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
margin: const EdgeInsets.symmetric(
horizontal: 15,
vertical: 15,
),
decoration: BoxDecoration(
color: ref.watch(themeProvider).themeColor.settingBgColor(),
borderRadius: const BorderRadius.all(
Radius.circular(15),
),
),
@@ -34,7 +37,7 @@ class _OtherPageState extends ConsumerState<OtherPage> {
children: [
Padding(
padding: const EdgeInsets.symmetric(
vertical: 10,
vertical: 8,
horizontal: 15,
),
child: Row(
@@ -59,7 +62,7 @@ class _OtherPageState extends ConsumerState<OtherPage> {
),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 10,
vertical: 8,
horizontal: 15,
),
child: Row(
@@ -84,7 +87,102 @@ class _OtherPageState extends ConsumerState<OtherPage> {
),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 10,
vertical: 8,
horizontal: 15,
),
child: Row(
children: [
Text(
"查看日志",
style: TextStyle(
color: ref.watch(themeProvider).themeColor.taskTitleColor(),
fontSize: 16,
),
),
const Spacer(),
const Icon(
CupertinoIcons.right_chevron,
size: 16,
),
],
),
),
],
),
),
Container(
margin: const EdgeInsets.symmetric(
horizontal: 15,
vertical: 15,
),
decoration: BoxDecoration(
color: ref.watch(themeProvider).themeColor.settingBgColor(),
borderRadius: const BorderRadius.all(
Radius.circular(15),
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(
top: 5,
bottom: 0,
left: 15,
right: 15,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"夜间模式",
style: TextStyle(
color: ref.watch(themeProvider).themeColor.taskTitleColor(),
fontSize: 16,
),
),
const Spacer(),
CupertinoSwitch(
value: ref.watch(themeProvider).isInDartMode(),
onChanged: (open) {
ref.watch(themeProvider).changeThemeReal(open);
}),
],
),
),
const Divider(
indent: 15,
),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 8,
horizontal: 15,
),
child: Row(
children: [
Text(
"查看日志",
style: TextStyle(
color: ref.watch(themeProvider).themeColor.taskTitleColor(),
fontSize: 16,
),
),
const Spacer(),
const Icon(
CupertinoIcons.right_chevron,
size: 16,
),
],
),
),
Divider(
indent: 15,
),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 8,
horizontal: 15,
),
child: Row(