feat: custom app font weight

Closes #533

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-03-26 21:39:58 +08:00
parent f5e9375917
commit 5d0b2dc8e3
9 changed files with 103 additions and 15 deletions

View File

@@ -146,6 +146,37 @@ List<SettingsModel> get styleSettings => [
defaultVal: false,
needReboot: true,
),
SettingsModel(
settingsType: SettingsType.sw1tch,
title: 'App字体字重',
subtitle: '点击设置',
setKey: SettingBoxKey.appFontWeight,
defaultVal: false,
onTap: () {
showDialog<double>(
context: Get.context!,
builder: (context) {
return SlideDialog(
title: 'App字体字重',
value: GStorage.appFontWeight.toDouble() + 1,
min: 1,
max: FontWeight.values.length.toDouble(),
divisions: FontWeight.values.length - 1,
);
},
).then((res) async {
if (res != null) {
await GStorage.setting
.put(SettingBoxKey.appFontWeight, res.toInt() - 1);
Get.forceAppUpdate();
}
});
},
leading: const Icon(Icons.text_fields),
onChanged: (value) {
Get.forceAppUpdate();
},
),
SettingsModel(
settingsType: SettingsType.sw1tch,
title: 'MD3样式底栏',

View File

@@ -36,20 +36,27 @@ class SetSwitchItem extends StatefulWidget {
class _SetSwitchItemState extends State<SetSwitchItem> {
late bool val;
@override
void didUpdateWidget(SetSwitchItem oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.setKey != widget.setKey) {
void setVal() {
if (widget.setKey == SettingBoxKey.appFontWeight) {
val = GStorage.appFontWeight != -1;
} else {
val = GStorage.setting
.get(widget.setKey, defaultValue: widget.defaultVal ?? false);
}
}
@override
void didUpdateWidget(SetSwitchItem oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.setKey != widget.setKey) {
setVal();
}
}
@override
void initState() {
super.initState();
val = GStorage.setting
.get(widget.setKey, defaultValue: widget.defaultVal ?? false);
setVal();
}
void switchChange(value) async {
@@ -89,7 +96,12 @@ class _SetSwitchItemState extends State<SetSwitchItem> {
val = value ?? !val;
await GStorage.setting.put(widget.setKey, val);
if (widget.setKey == SettingBoxKey.appFontWeight) {
await GStorage.setting.put(SettingBoxKey.appFontWeight, val ? 4 : -1);
} else {
await GStorage.setting.put(widget.setKey, val);
}
widget.onChanged?.call(val);
if (widget.needReboot == true) {
SmartDialog.showToast('重启生效');