Skip to content

Commit 1b232d0

Browse files
committed
增加主题切换支持
1 parent 86194a7 commit 1b232d0

2 files changed

Lines changed: 57 additions & 13 deletions

File tree

‎lib/common/style/GSYStyle.dart‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,18 @@ class GSYColors {
4545

4646
///文本样式
4747
class GSYConstant {
48-
4948
static const lagerTextSize = 30.0;
5049
static const bigTextSize = 23.0;
5150
static const normalTextSize = 18.0;
5251
static const middleTextWhiteSize = 16.0;
5352
static const smallTextSize = 14.0;
5453
static const minTextSize = 12.0;
5554

56-
5755
static const minText = TextStyle(
5856
color: Color(GSYColors.subTextColor),
5957
fontSize: minTextSize,
6058
);
6159

62-
63-
6460
static const smallTextWhite = TextStyle(
6561
color: Color(GSYColors.textColorWhite),
6662
fontSize: smallTextSize,
@@ -97,8 +93,6 @@ class GSYConstant {
9793
fontSize: smallTextSize,
9894
);
9995

100-
101-
10296
static const middleText = TextStyle(
10397
color: Color(GSYColors.mainTextColor),
10498
fontSize: middleTextWhiteSize,
@@ -137,7 +131,6 @@ class GSYConstant {
137131
fontWeight: FontWeight.bold,
138132
);
139133

140-
141134
static const normalText = TextStyle(
142135
color: Color(GSYColors.mainTextColor),
143136
fontSize: normalTextSize,
@@ -176,8 +169,6 @@ class GSYConstant {
176169
fontSize: normalTextSize,
177170
);
178171

179-
180-
181172
static const largeText = TextStyle(
182173
color: Color(GSYColors.mainTextColor),
183174
fontSize: bigTextSize,
@@ -200,9 +191,6 @@ class GSYConstant {
200191
fontWeight: FontWeight.bold,
201192
);
202193

203-
204-
205-
206194
static const largeLargeTextWhite = TextStyle(
207195
color: Color(GSYColors.textColorWhite),
208196
fontSize: lagerTextSize,
@@ -254,6 +242,15 @@ class GSYStrings {
254242
static const String home_check_update = "检测更新";
255243
static const String home_history = "阅读历史";
256244
static const String home_user_info = "个人信息";
245+
static const String home_change_theme = "切换主题";
246+
247+
static const String home_theme_default = "默认主题";
248+
static const String home_theme_1 = "主题1";
249+
static const String home_theme_2 = "主题2";
250+
static const String home_theme_3 = "主题3";
251+
static const String home_theme_4 = "主题4";
252+
static const String home_theme_5 = "主题5";
253+
static const String home_theme_6 = "主题6";
257254

258255
static const String login_username_hint_text = "请输入github用户名";
259256
static const String login_password_hint_text = "请输入密码";

‎lib/widget/HomeDrawer.dart‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
1212
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
1313
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
1414
import 'package:gsy_github_app_flutter/widget/GSYFlexButton.dart';
15+
import 'package:redux/redux.dart';
1516

1617
/**
1718
* 主页drawer
@@ -31,6 +32,45 @@ class HomeDrawer extends StatelessWidget {
3132
));
3233
}
3334

35+
showThemeDialog(BuildContext context, Store store) {
36+
List<String> list = [
37+
GSYStrings.home_theme_default,
38+
GSYStrings.home_theme_1,
39+
GSYStrings.home_theme_2,
40+
GSYStrings.home_theme_3,
41+
GSYStrings.home_theme_4,
42+
GSYStrings.home_theme_5,
43+
GSYStrings.home_theme_6,
44+
];
45+
CommonUtils.showCommitOptionDialog(context, list, (index) {
46+
ThemeData themeData;
47+
switch (index) {
48+
case 0:
49+
themeData = new ThemeData(primarySwatch: GSYColors.primarySwatch);
50+
break;
51+
case 1:
52+
themeData = new ThemeData(primarySwatch: Colors.brown);
53+
break;
54+
case 2:
55+
themeData = new ThemeData(primarySwatch: Colors.blue);
56+
break;
57+
case 3:
58+
themeData = new ThemeData(primarySwatch: Colors.teal);
59+
break;
60+
case 4:
61+
themeData = new ThemeData(primarySwatch: Colors.amber);
62+
break;
63+
case 5:
64+
themeData = new ThemeData(primarySwatch: Colors.blueGrey);
65+
break;
66+
case 6:
67+
themeData = new ThemeData(primarySwatch: Colors.deepOrange);
68+
break;
69+
}
70+
store.dispatch(new RefreshThemeDataAction(themeData));
71+
});
72+
}
73+
3474
@override
3575
Widget build(BuildContext context) {
3676
return new StoreBuilder<GSYState>(
@@ -109,6 +149,14 @@ class HomeDrawer extends StatelessWidget {
109149
onTap: () {
110150
NavigatorUtils.gotoUserProfileInfo(context);
111151
}),
152+
new ListTile(
153+
title: new Text(
154+
GSYStrings.home_change_theme,
155+
style: GSYConstant.normalText,
156+
),
157+
onTap: () {
158+
showThemeDialog(context, store);
159+
}),
112160
new ListTile(
113161
title: new Text(
114162
GSYStrings.home_check_update,
@@ -126,7 +174,6 @@ class HomeDrawer extends StatelessWidget {
126174
GetVersion.projectVersion.then((value) {
127175
showAboutDialog(context, value);
128176
});
129-
store.dispatch(new RefreshThemeDataAction(new ThemeData(primarySwatch: Colors.blue)));
130177
}),
131178
new ListTile(
132179
title: new GSYFlexButton(

0 commit comments

Comments
 (0)