Skip to content

Commit

Permalink
重构代码
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjianxiandev committed Apr 13, 2020
1 parent 1bb08b2 commit 7ad29a6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class _MainPageState extends State<MainPage> {
Provider.of<ThemeModel>(context).updateThemeColor(getThemeColors()[index]);
});
queryDark().then((value) {
Provider.of<DarkMode>(context).setDark(value);
Provider.of<DarkMode>(context).updateDarkMode(value);
if (value) {
Provider.of<ThemeModel>(context).updateThemeColor(Color(0xff323638));
}
Expand Down
16 changes: 1 addition & 15 deletions lib/page/setting/setting_fragment.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:wanandroidflutter/application.dart';
import 'package:wanandroidflutter/constant/Constants.dart';
import 'package:wanandroidflutter/generated/l10n.dart';
import 'package:wanandroidflutter/theme/font_model.dart';
import 'package:wanandroidflutter/theme/locale_model.dart';
import 'package:wanandroidflutter/theme/theme_colors.dart';
import 'package:wanandroidflutter/theme/theme_model.dart';
import 'package:wanandroidflutter/theme/dark_model.dart';
import 'package:wanandroidflutter/utils/Config.dart';
Expand Down Expand Up @@ -60,10 +58,9 @@ class _SettingFragmentState extends State<SettingFragment> {
value: Provider.of<DarkMode>(context).isDark,
onChanged: (value) {
print("value = $value");
Provider.of<DarkMode>(context).setDark(value);
Provider.of<DarkMode>(context).updateDarkMode(value);
appTheme.updateThemeColor(
value ? Color(0xff323638) : beforeChangeColor);
saveDarkMode(value);
}),
),
),
Expand Down Expand Up @@ -96,7 +93,6 @@ class _SettingFragmentState extends State<SettingFragment> {
onChanged: (index) {
print("index = $index");
Provider.of<FontModel>(context).updateFontIndex(index);
saveFontMode(index);
},
groupValue: Provider.of<FontModel>(context).fontIndex,
title: Text(index == 0? S.of(context).normol_font : S.of(context).kuaile_font),
Expand Down Expand Up @@ -195,16 +191,6 @@ class _SettingFragmentState extends State<SettingFragment> {
);
}

void saveDarkMode(bool value) async {
print("dark = $value");
Application.sp.putBool(Config.SP_DARK_MODEL, value);
}

void saveFontMode(int index) async {
print("fontIndex = $index");
Application.sp.putInt(Config.SP_FONT_INDEX, index);
}

void saveBeforeChangeTheme(Color color) async {
Application.sp.putInt(Config.SP_BEFORE_CHANGE_DARK_MODE, color.value);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/theme/dark_model.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import 'package:flutter/material.dart';
import 'package:wanandroidflutter/application.dart';
import 'package:wanandroidflutter/utils/Config.dart';

class DarkMode with ChangeNotifier {
bool _isDark = false;

get isDark => _isDark;

void setDark(isDark) {
void updateDarkMode(isDark) {
_isDark = isDark;
notifyListeners();
Application.sp.putBool(Config.SP_DARK_MODEL, isDark);
}
}
3 changes: 3 additions & 0 deletions lib/theme/font_model.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:wanandroidflutter/application.dart';
import 'package:wanandroidflutter/utils/Config.dart';

class FontModel with ChangeNotifier {
int _fontIndex;
Expand All @@ -8,5 +10,6 @@ class FontModel with ChangeNotifier {
void updateFontIndex(int fontIndex) {
this._fontIndex = fontIndex;
notifyListeners();
Application.sp.putInt(Config.SP_FONT_INDEX, fontIndex);
}
}

0 comments on commit 7ad29a6

Please sign in to comment.