1
- // Flutter imports:
2
- import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'
3
- as mdi;
4
-
5
1
// Package imports:
6
- import 'package:device_info_plus/device_info_plus.dart' ;
7
2
import 'package:fluent_ui/fluent_ui.dart' ;
8
3
import 'package:flutter_riverpod/flutter_riverpod.dart' ;
9
4
import 'package:flutter_screenutil/flutter_screenutil.dart' ;
10
5
import 'package:package_info_plus/package_info_plus.dart' ;
11
- import 'package:url_launcher/url_launcher_string.dart' ;
12
6
13
7
// Project imports:
14
- import '../../store/app_store.dart' ;
15
- import '../../tools/log_tool.dart' ;
16
- import '../../ui/bt_icon.dart' ;
17
- import '../../utils/get_theme_label.dart' ;
18
- import '../../widgets/config/app_config_bgm.dart' ;
8
+ import '../../widgets/app/config/app_config_bgm.dart' ;
9
+ import '../../widgets/app/config/app_config_device.dart' ;
10
+ import '../../widgets/app/config/app_config_info.dart' ;
19
11
20
12
/// 设置页面
21
13
class SettingPage extends ConsumerStatefulWidget {
@@ -32,15 +24,6 @@ class _SettingPageState extends ConsumerState<SettingPage>
32
24
/// 应用信息
33
25
PackageInfo ? packageInfo;
34
26
35
- /// 设备信息
36
- WindowsDeviceInfo ? deviceInfo;
37
-
38
- /// 当前主题
39
- ThemeMode get curThemeMode => ref.watch (appStoreProvider).themeMode;
40
-
41
- /// 当前主题色
42
- AccentColor get curAccentColor => ref.watch (appStoreProvider).accentColor;
43
-
44
27
/// 保存状态
45
28
@override
46
29
bool get wantKeepAlive => false ;
@@ -51,125 +34,10 @@ class _SettingPageState extends ConsumerState<SettingPage>
51
34
super .initState ();
52
35
Future .microtask (() async {
53
36
packageInfo = await PackageInfo .fromPlatform ();
54
- deviceInfo = await DeviceInfoPlugin ().windowsInfo;
55
37
setState (() {});
56
38
});
57
39
}
58
40
59
- /// 构建 Windows 设备信息
60
- Widget buildWinDeviceInfo (WindowsDeviceInfo diw) {
61
- return Expander (
62
- leading: Icon (mdi.MdiIcons .laptopAccount),
63
- header: Text (diw.productName),
64
- content: Column (
65
- children: [
66
- ListTile (
67
- leading: Icon (mdi.MdiIcons .laptop),
68
- title: const Text ('所在平台' ),
69
- subtitle: Text (
70
- 'Windows ${diw .displayVersion } '
71
- '${diw .majorVersion }.${diw .minorVersion }.${diw .buildNumber }'
72
- '(${diw .buildLab })' ,
73
- ),
74
- ),
75
- ListTile (
76
- leading: Icon (mdi.MdiIcons .devices),
77
- title: const Text ('设备' ),
78
- subtitle: Text ('${diw .computerName } ${diw .productId }' ),
79
- ),
80
- ListTile (
81
- leading: Icon (mdi.MdiIcons .identifier),
82
- title: const Text ('标识符' ),
83
- subtitle: Text (
84
- diw.deviceId.substring (1 , diw.deviceId.length - 1 ),
85
- ),
86
- ),
87
- ],
88
- ),
89
- );
90
- }
91
-
92
- /// 设备信息项
93
- Widget buildDeviceInfo () {
94
- if (deviceInfo != null ) return buildWinDeviceInfo (deviceInfo! );
95
- return const ListTile (title: Text ('设备信息' ), subtitle: Text ('未知设备' ));
96
- }
97
-
98
- /// 构建主题项Flyout
99
- MenuFlyoutItem buildThemeFlyout (ThemeModeConfig theme) {
100
- return MenuFlyoutItem (
101
- text: Text (theme.label),
102
- leading: Icon (theme.icon),
103
- onPressed: () async {
104
- await ref.read (appStoreProvider.notifier).setThemeMode (theme.cur);
105
- },
106
- selected: curThemeMode == theme.cur,
107
- trailing:
108
- curThemeMode == theme.cur ? BtIcon (FluentIcons .check_mark) : null ,
109
- );
110
- }
111
-
112
- /// 构建主题切换
113
- Widget buildThemeSwitch () {
114
- var themes = getThemeModeConfigList ();
115
- var curTheme = getThemeModeConfig (curThemeMode);
116
- return ListTile (
117
- leading: Icon (curTheme.icon),
118
- title: const Text ('主题模式' ),
119
- subtitle: Text (curTheme.label),
120
- trailing: DropDownButton (
121
- title: Text (curTheme.label),
122
- items: themes.map (buildThemeFlyout).toList (),
123
- ),
124
- );
125
- }
126
-
127
- /// 构建主题色切换展开
128
- Widget buildColorFlyout (AccentColor color) {
129
- return Button (
130
- autofocus: curAccentColor == color,
131
- style: ButtonStyle (padding: WidgetStatePropertyAll (EdgeInsets .zero)),
132
- onPressed: () async {
133
- await ref.read (appStoreProvider.notifier).setAccentColor (color);
134
- if (mounted) Navigator .of (context).pop ();
135
- },
136
- child: SizedBox (
137
- width: 32. spMax,
138
- height: 32. spMax,
139
- child: ColoredBox (color: color),
140
- ),
141
- );
142
- }
143
-
144
- /// 构建主题色切换
145
- Widget buildColorSwitch () {
146
- return ListTile (
147
- leading: const Icon (FluentIcons .color),
148
- title: const Text ('主题色' ),
149
- subtitle: Text (
150
- curAccentColor.value.toRadixString (16 ),
151
- style: TextStyle (color: curAccentColor),
152
- ),
153
- trailing: SplitButton (
154
- flyout: FlyoutContent (
155
- constraints: BoxConstraints (maxWidth: 200. w),
156
- child: curThemeMode == ThemeMode .system
157
- ? const Text ('跟随系统设置\r\n 无法更改' )
158
- : Wrap (
159
- runSpacing: 8. h,
160
- spacing: 8. w,
161
- children: Colors .accentColors.map (buildColorFlyout).toList (),
162
- ),
163
- ),
164
- child: SizedBox (
165
- width: 32. spMax,
166
- height: 32. spMax,
167
- child: ColoredBox (color: curAccentColor),
168
- ),
169
- ),
170
- );
171
- }
172
-
173
41
/// 构建应用徽章
174
42
Widget buildAppBadge (BuildContext context) {
175
43
var shadow = const Shadow (
@@ -178,24 +46,21 @@ class _SettingPageState extends ConsumerState<SettingPage>
178
46
blurRadius: 2 ,
179
47
);
180
48
return Container (
181
- padding: EdgeInsets .symmetric (horizontal: 16. w, vertical: 16. h),
182
49
decoration: BoxDecoration (
183
- borderRadius: BorderRadius .circular (10 ),
184
- color: curAccentColor ,
50
+ borderRadius: BorderRadius .circular (8 ),
51
+ color: FluentTheme . of (context).accentColor ,
185
52
),
53
+ padding: EdgeInsets .all (16 ),
186
54
child: Column (
187
55
mainAxisSize: MainAxisSize .min,
188
56
crossAxisAlignment: CrossAxisAlignment .center,
189
57
mainAxisAlignment: MainAxisAlignment .center,
190
58
children: [
191
- HyperlinkButton (
192
- child: Image .asset ('assets/images/logo.png' , width: 100. w),
193
- onPressed: () {
194
- launchUrlString ('https://github.com/BTMuli/BangumiToday' );
195
- },
196
- ),
59
+ Image .asset ('assets/images/logo.png' , width: 100. w),
197
60
Text (
198
- 'BangumiToday' ,
61
+ 'BangumiToday '
62
+ '${packageInfo ?.version ?? '0.0.0' }'
63
+ '+${packageInfo ?.buildNumber ?? '' }' ,
199
64
style: TextStyle (
200
65
color: Colors .white,
201
66
fontSize: 20 ,
@@ -204,12 +69,6 @@ class _SettingPageState extends ConsumerState<SettingPage>
204
69
),
205
70
),
206
71
SizedBox (height: 8. h),
207
- Text (
208
- 'Version: ${packageInfo ?.version } '
209
- 'Build: ${packageInfo ?.buildNumber }' ,
210
- style: TextStyle (color: Colors .white, shadows: [shadow]),
211
- ),
212
- SizedBox (height: 8. h),
213
72
Text (
214
73
'©2024 BTMuli<[email protected] >' ,
215
74
style: TextStyle (color: Colors .white, shadows: [shadow]),
@@ -219,58 +78,11 @@ class _SettingPageState extends ConsumerState<SettingPage>
219
78
);
220
79
}
221
80
222
- /// 构建应用信息
223
- Widget buildAppInfo () {
224
- return Column (
225
- crossAxisAlignment: CrossAxisAlignment .center,
226
- mainAxisAlignment: MainAxisAlignment .start,
227
- mainAxisSize: MainAxisSize .max,
228
- children: [
229
- buildAppBadge (context),
230
- SizedBox (height: 16. h),
231
- Row (
232
- mainAxisSize: MainAxisSize .max,
233
- crossAxisAlignment: CrossAxisAlignment .center,
234
- mainAxisAlignment: MainAxisAlignment .spaceBetween,
235
- children: [
236
- Tooltip (
237
- message: 'Github' ,
238
- child: Button (
239
- onPressed: () async {
240
- await launchUrlString (
241
- 'https://github.com/BTMuli/BangumiToday' );
242
- },
243
- child: BtIcon (mdi.MdiIcons .github),
244
- ),
245
- ),
246
- SizedBox (width: 16. w),
247
- Tooltip (
248
- message: '日志' ,
249
- child: Button (
250
- onPressed: BTLogTool ().openLogDir,
251
- child: BtIcon (mdi.MdiIcons .faceAgent),
252
- ),
253
- ),
254
- ],
255
- ),
256
- ],
257
- );
258
- }
259
-
260
- /// 构建应用配置
261
- Widget buildAppConfig () {
262
- return Expander (
263
- leading: const Icon (FluentIcons .settings),
264
- header: const Text ('应用配置' ),
265
- content: Column (children: [buildThemeSwitch (), buildColorSwitch ()]),
266
- );
267
- }
268
-
269
81
/// 构建配置项
270
82
List <Widget > buildConfigList () {
271
83
return [
272
- buildDeviceInfo (),
273
- buildAppConfig (),
84
+ AppConfigInfoWidget (),
85
+ AppConfigDeviceWidget (),
274
86
AppConfigBgmWidget (),
275
87
];
276
88
}
@@ -281,19 +93,20 @@ class _SettingPageState extends ConsumerState<SettingPage>
281
93
super .build (context);
282
94
var configList = buildConfigList ();
283
95
return ScaffoldPage .withPadding (
284
- padding: EdgeInsets .symmetric (horizontal : 12. w, vertical : 16. h ),
96
+ padding: EdgeInsets .all ( 8 ),
285
97
content: Row (
286
98
crossAxisAlignment: CrossAxisAlignment .start,
287
99
mainAxisAlignment: MainAxisAlignment .spaceBetween,
288
100
children: [
289
101
Flexible (
290
102
child: ListView .separated (
291
- itemBuilder: (_, int idx) => configList[idx],
292
- separatorBuilder: (_, __) => SizedBox (height: 12. h),
293
- itemCount: configList.length),
103
+ itemBuilder: (_, int idx) => configList[idx],
104
+ separatorBuilder: (_, __) => const SizedBox (height: 8 ),
105
+ itemCount: configList.length,
106
+ ),
294
107
),
295
- SizedBox (width: 12. w ),
296
- buildAppInfo ( ),
108
+ const SizedBox (width: 12 ),
109
+ buildAppBadge (context ),
297
110
],
298
111
),
299
112
);
0 commit comments