1
1
import 'package:fl_clash/common/common.dart' ;
2
+ import 'package:fl_clash/enum/enum.dart' ;
2
3
import 'package:fl_clash/models/models.dart' ;
3
4
import 'package:fl_clash/state.dart' ;
4
5
import 'package:flutter/material.dart' ;
@@ -18,6 +19,16 @@ class ThemeModeItem {
18
19
});
19
20
}
20
21
22
+ class FontFamilyItem {
23
+ final FontFamily fontFamily;
24
+ final String label;
25
+
26
+ const FontFamilyItem ({
27
+ required this .fontFamily,
28
+ required this .label,
29
+ });
30
+ }
31
+
21
32
class ThemeFragment extends StatelessWidget {
22
33
const ThemeFragment ({super .key});
23
34
@@ -92,7 +103,11 @@ class _ThemeColorsBoxState extends State<ThemeColorsBox> {
92
103
return CommonCard (
93
104
isSelected: isSelected,
94
105
onPressed: () {
95
- globalState.appController.config.themeMode = themeModeItem.themeMode;
106
+ final appController = globalState.appController;
107
+ appController.config.themeProps =
108
+ appController.config.themeProps.copyWith (
109
+ themeMode: themeModeItem.themeMode,
110
+ );
96
111
},
97
112
child: Padding (
98
113
padding: const EdgeInsets .symmetric (horizontal: 16 ),
@@ -125,8 +140,42 @@ class _ThemeColorsBoxState extends State<ThemeColorsBox> {
125
140
isSelected: isSelected,
126
141
primaryColor: color,
127
142
onPressed: () {
128
- globalState.appController.config.primaryColor = color? .value;
143
+ final appController = globalState.appController;
144
+ appController.config.themeProps =
145
+ appController.config.themeProps.copyWith (
146
+ primaryColor: color? .value,
147
+ );
148
+ },
149
+ );
150
+ }
151
+
152
+ Widget _fontFamilyCheckBox ({
153
+ bool ? isSelected,
154
+ required FontFamilyItem fontFamilyItem,
155
+ }) {
156
+ return CommonCard (
157
+ isSelected: isSelected,
158
+ onPressed: () {
159
+ final appController = globalState.appController;
160
+ appController.config.themeProps =
161
+ appController.config.themeProps.copyWith (
162
+ fontFamily: fontFamilyItem.fontFamily,
163
+ );
129
164
},
165
+ child: Padding (
166
+ padding: const EdgeInsets .symmetric (horizontal: 8 ),
167
+ child: Row (
168
+ mainAxisSize: MainAxisSize .min,
169
+ mainAxisAlignment: MainAxisAlignment .start,
170
+ children: [
171
+ Flexible (
172
+ child: Text (
173
+ fontFamilyItem.label,
174
+ ),
175
+ ),
176
+ ],
177
+ ),
178
+ ),
130
179
);
131
180
}
132
181
@@ -158,15 +207,59 @@ class _ThemeColorsBoxState extends State<ThemeColorsBox> {
158
207
Colors .yellowAccent,
159
208
Colors .purple,
160
209
];
210
+ List <FontFamilyItem > fontFamilyItems = [
211
+ FontFamilyItem (
212
+ label: appLocalizations.systemFont,
213
+ fontFamily: FontFamily .system,
214
+ ),
215
+ const FontFamilyItem (
216
+ label: "MiSans" ,
217
+ fontFamily: FontFamily .miSans,
218
+ ),
219
+ ];
161
220
return Column (
162
221
children: [
222
+ ItemCard (
223
+ info: Info (
224
+ label: appLocalizations.fontFamily,
225
+ iconData: Icons .text_fields,
226
+ ),
227
+ child: Container (
228
+ margin: const EdgeInsets .only (
229
+ left: 16 ,
230
+ right: 16 ,
231
+ ),
232
+ height: 48 ,
233
+ child: Selector <Config , FontFamily >(
234
+ selector: (_, config) => config.themeProps.fontFamily,
235
+ builder: (_, fontFamily, __) {
236
+ return ListView .separated (
237
+ scrollDirection: Axis .horizontal,
238
+ itemBuilder: (_, index) {
239
+ final fontFamilyItem = fontFamilyItems[index];
240
+ return _fontFamilyCheckBox (
241
+ isSelected: fontFamily == fontFamilyItem.fontFamily,
242
+ fontFamilyItem: fontFamilyItem,
243
+ );
244
+ },
245
+ separatorBuilder: (_, __) {
246
+ return const SizedBox (
247
+ width: 16 ,
248
+ );
249
+ },
250
+ itemCount: fontFamilyItems.length,
251
+ );
252
+ },
253
+ ),
254
+ ),
255
+ ),
163
256
ItemCard (
164
257
info: Info (
165
258
label: appLocalizations.themeMode,
166
259
iconData: Icons .brightness_high,
167
260
),
168
261
child: Selector <Config , ThemeMode >(
169
- selector: (_, config) => config.themeMode,
262
+ selector: (_, config) => config.themeProps. themeMode,
170
263
builder: (_, themeMode, __) {
171
264
return Container (
172
265
padding: const EdgeInsets .symmetric (horizontal: 16 ),
@@ -204,7 +297,7 @@ class _ThemeColorsBoxState extends State<ThemeColorsBox> {
204
297
),
205
298
height: 88 ,
206
299
child: Selector <Config , int ?>(
207
- selector: (_, config) => config.primaryColor,
300
+ selector: (_, config) => config.themeProps. primaryColor,
208
301
builder: (_, currentPrimaryColor, __) {
209
302
return ListView .separated (
210
303
scrollDirection: Axis .horizontal,
@@ -229,7 +322,7 @@ class _ThemeColorsBoxState extends State<ThemeColorsBox> {
229
322
Padding (
230
323
padding: const EdgeInsets .symmetric (vertical: 16 ),
231
324
child: Selector <Config , bool >(
232
- selector: (_, config) => config.prueBlack,
325
+ selector: (_, config) => config.themeProps. prueBlack,
233
326
builder: (_, value, ___) {
234
327
return ListItem .switchItem (
235
328
leading: Icon (
@@ -238,63 +331,19 @@ class _ThemeColorsBoxState extends State<ThemeColorsBox> {
238
331
),
239
332
title: Text (appLocalizations.prueBlackMode),
240
333
delegate: SwitchDelegate (
241
- value: value,
242
- onChanged: (value) {
243
- globalState.appController.config.prueBlack = value;
244
- }),
334
+ value: value,
335
+ onChanged: (value) {
336
+ final appController = globalState.appController;
337
+ appController.config.themeProps =
338
+ appController.config.themeProps.copyWith (
339
+ prueBlack: value,
340
+ );
341
+ },
342
+ ),
245
343
);
246
344
},
247
345
),
248
346
),
249
- // Padding(
250
- // padding: const EdgeInsets.symmetric(vertical: 16),
251
- // child: Selector<Config, bool>(
252
- // selector: (_, config) => config.scaleProps.custom,
253
- // builder: (_, value, ___) {
254
- // return ListItem.switchItem(
255
- // leading: Icon(
256
- // Icons.format_size_sharp,
257
- // color: context.colorScheme.primary,
258
- // ),
259
- // title: const Text("自定义字体大小"),
260
- // delegate: SwitchDelegate(
261
- // value: value,
262
- // onChanged: (value) {
263
- // globalState.appController.config.scaleProps =
264
- // globalState.appController.config.scaleProps.copyWith(
265
- // custom: value,
266
- // );
267
- // },
268
- // ),
269
- // );
270
- // },
271
- // ),
272
- // ),
273
- // SizedBox(
274
- // height: 20,
275
- // child: Selector<Config, ScaleProps>(
276
- // selector: (_, config) => config.scaleProps,
277
- // builder: (_, props, ___) {
278
- // return AbsorbPointer(
279
- // absorbing: !props.custom,
280
- // child: DisabledMask(
281
- // status: !props.custom,
282
- // child: Slider(
283
- // value: props.scale,
284
- // min: 0.8,
285
- // max: 1.2,
286
- // onChanged: (value) {
287
- // globalState.appController.config.scaleProps =
288
- // globalState.appController.config.scaleProps.copyWith(
289
- // scale: value,
290
- // );
291
- // },
292
- // ),
293
- // ),
294
- // );
295
- // },
296
- // ),
297
- // ),
298
347
const SizedBox (
299
348
height: 64 ,
300
349
),
0 commit comments