Skip to content

Commit 526ccdf

Browse files
committed
Fix the collapse issues
Add fontFamily options
1 parent 8282a9a commit 526ccdf

21 files changed

+489
-141
lines changed

assets/fonts/MiSans-Regular.ttf

7.7 MB
Binary file not shown.

core/common.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,12 @@ func getRawConfigWithId(id string) *config.RawConfig {
158158
}
159159
mapping["path"] = filepath.Join(getProfileProvidersPath(id), value)
160160
if configParams.TestURL != nil {
161-
hc := mapping["health-check"].(map[string]any)
162-
if hc != nil {
163-
if hc["url"] != nil {
164-
hc["url"] = *configParams.TestURL
161+
if mapping["health-check"] != nil {
162+
hc := mapping["health-check"].(map[string]any)
163+
if hc != nil {
164+
if hc["url"] != nil {
165+
hc["url"] = *configParams.TestURL
166+
}
165167
}
166168
}
167169
}

lib/application.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,10 @@ class ApplicationState extends State<Application> {
163163
child: Selector2<AppState, Config, ApplicationSelectorState>(
164164
selector: (_, appState, config) => ApplicationSelectorState(
165165
locale: config.appSetting.locale,
166-
themeMode: config.themeMode,
167-
primaryColor: config.primaryColor,
168-
prueBlack: config.prueBlack,
166+
themeMode: config.themeProps.themeMode,
167+
primaryColor: config.themeProps.primaryColor,
168+
prueBlack: config.themeProps.prueBlack,
169+
fontFamily: config.themeProps.fontFamily,
169170
),
170171
builder: (_, state, child) {
171172
return DynamicColorBuilder(
@@ -199,6 +200,7 @@ class ApplicationState extends State<Application> {
199200
themeMode: state.themeMode,
200201
theme: ThemeData(
201202
useMaterial3: true,
203+
fontFamily: state.fontFamily.value,
202204
pageTransitionsTheme: _pageTransitionsTheme,
203205
colorScheme: _getAppColorScheme(
204206
brightness: Brightness.light,
@@ -208,6 +210,7 @@ class ApplicationState extends State<Application> {
208210
),
209211
darkTheme: ThemeData(
210212
useMaterial3: true,
213+
fontFamily: state.fontFamily.value,
211214
pageTransitionsTheme: _pageTransitionsTheme,
212215
colorScheme: _getAppColorScheme(
213216
brightness: Brightness.dark,

lib/common/common.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,4 @@ export 'scroll.dart';
2929
export 'icons.dart';
3030
export 'http.dart';
3131
export 'keyboard.dart';
32-
export 'network.dart';
33-
export 'font.dart';
32+
export 'network.dart';

lib/common/font.dart

Lines changed: 0 additions & 3 deletions
This file was deleted.

lib/enum/enum.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,14 @@ enum ProxiesIconStyle {
162162
none,
163163
icon,
164164
}
165+
166+
enum FontFamily {
167+
system(),
168+
miSans("MiSans"),
169+
twEmoji("Twemoji"),
170+
icon("Icons");
171+
172+
final String? value;
173+
174+
const FontFamily([this.value]);
175+
}

lib/fragments/dashboard/network_detection.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22

33
import 'package:dio/dio.dart';
44
import 'package:fl_clash/common/common.dart';
5+
import 'package:fl_clash/enum/enum.dart';
56
import 'package:fl_clash/models/models.dart';
67
import 'package:fl_clash/state.dart';
78
import 'package:fl_clash/widgets/widgets.dart';
@@ -69,7 +70,7 @@ class _NetworkDetectionState extends State<NetworkDetection> {
6970
}
7071

7172
_clearSetTimeoutTimer() {
72-
if(_setTimeoutTimer != null){
73+
if (_setTimeoutTimer != null) {
7374
_setTimeoutTimer?.cancel();
7475
_setTimeoutTimer = null;
7576
}
@@ -155,7 +156,7 @@ class _NetworkDetectionState extends State<NetworkDetection> {
155156
.textTheme
156157
.titleLarge
157158
?.copyWith(
158-
fontFamily: Fonts.twEmoji,
159+
fontFamily: FontFamily.twEmoji.value,
159160
),
160161
),
161162
)

lib/fragments/theme.dart

Lines changed: 107 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:fl_clash/common/common.dart';
2+
import 'package:fl_clash/enum/enum.dart';
23
import 'package:fl_clash/models/models.dart';
34
import 'package:fl_clash/state.dart';
45
import 'package:flutter/material.dart';
@@ -18,6 +19,16 @@ class ThemeModeItem {
1819
});
1920
}
2021

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+
2132
class ThemeFragment extends StatelessWidget {
2233
const ThemeFragment({super.key});
2334

@@ -92,7 +103,11 @@ class _ThemeColorsBoxState extends State<ThemeColorsBox> {
92103
return CommonCard(
93104
isSelected: isSelected,
94105
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+
);
96111
},
97112
child: Padding(
98113
padding: const EdgeInsets.symmetric(horizontal: 16),
@@ -125,8 +140,42 @@ class _ThemeColorsBoxState extends State<ThemeColorsBox> {
125140
isSelected: isSelected,
126141
primaryColor: color,
127142
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+
);
129164
},
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+
),
130179
);
131180
}
132181

@@ -158,15 +207,59 @@ class _ThemeColorsBoxState extends State<ThemeColorsBox> {
158207
Colors.yellowAccent,
159208
Colors.purple,
160209
];
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+
];
161220
return Column(
162221
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+
),
163256
ItemCard(
164257
info: Info(
165258
label: appLocalizations.themeMode,
166259
iconData: Icons.brightness_high,
167260
),
168261
child: Selector<Config, ThemeMode>(
169-
selector: (_, config) => config.themeMode,
262+
selector: (_, config) => config.themeProps.themeMode,
170263
builder: (_, themeMode, __) {
171264
return Container(
172265
padding: const EdgeInsets.symmetric(horizontal: 16),
@@ -204,7 +297,7 @@ class _ThemeColorsBoxState extends State<ThemeColorsBox> {
204297
),
205298
height: 88,
206299
child: Selector<Config, int?>(
207-
selector: (_, config) => config.primaryColor,
300+
selector: (_, config) => config.themeProps.primaryColor,
208301
builder: (_, currentPrimaryColor, __) {
209302
return ListView.separated(
210303
scrollDirection: Axis.horizontal,
@@ -229,7 +322,7 @@ class _ThemeColorsBoxState extends State<ThemeColorsBox> {
229322
Padding(
230323
padding: const EdgeInsets.symmetric(vertical: 16),
231324
child: Selector<Config, bool>(
232-
selector: (_, config) => config.prueBlack,
325+
selector: (_, config) => config.themeProps.prueBlack,
233326
builder: (_, value, ___) {
234327
return ListItem.switchItem(
235328
leading: Icon(
@@ -238,63 +331,19 @@ class _ThemeColorsBoxState extends State<ThemeColorsBox> {
238331
),
239332
title: Text(appLocalizations.prueBlackMode),
240333
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+
),
245343
);
246344
},
247345
),
248346
),
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-
// ),
298347
const SizedBox(
299348
height: 64,
300349
),

lib/l10n/arb/intl_en.arb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,5 +320,7 @@
320320
"iconConfiguration": "Icon configuration",
321321
"noData": "No data",
322322
"adminAutoLaunch": "Admin auto launch",
323-
"adminAutoLaunchDesc": "Boot up by using admin mode"
323+
"adminAutoLaunchDesc": "Boot up by using admin mode",
324+
"fontFamily": "FontFamily",
325+
"systemFont": "System font"
324326
}

lib/l10n/arb/intl_zh_CN.arb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,5 +320,7 @@
320320
"iconConfiguration": "图片配置",
321321
"noData": "暂无数据",
322322
"adminAutoLaunch": "管理员自启动",
323-
"adminAutoLaunchDesc": "使用管理员模式开机自启动"
323+
"adminAutoLaunchDesc": "使用管理员模式开机自启动",
324+
"fontFamily": "字体",
325+
"systemFont": "系统字体"
324326
}

0 commit comments

Comments
 (0)