improve: 设置页面样式改进

- 下拉选择改为dialog, 参考 Android 系统内部设置关于选项的行为
- 一些列表对齐问题
- 字体设置预览文字居中
This commit is contained in:
gumengyu
2023-12-15 13:22:51 +08:00
parent 4217fa26e2
commit a14283260e
7 changed files with 220 additions and 201 deletions

View File

@ -4,6 +4,8 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:pilipala/models/common/theme_type.dart';
import 'package:pilipala/pages/setting/pages/color_select.dart';
import 'package:pilipala/pages/setting/widgets/select_dialog.dart';
import 'package:pilipala/utils/storage.dart';
import 'controller.dart';
@ -18,6 +20,8 @@ class StyleSetting extends StatefulWidget {
class _StyleSettingState extends State<StyleSetting> {
final SettingController settingController = Get.put(SettingController());
final ColorSelectController colorSelectController = Get.put(ColorSelectController());
Box setting = GStrorage.setting;
late int picQuality;
late ThemeType _tempThemeValue;
@ -56,6 +60,7 @@ class _StyleSettingState extends State<StyleSetting> {
title: const Text('震动反馈'),
subtitle: Text('请确定手机设置中已开启震动反馈', style: subTitleStyle),
trailing: Transform.scale(
alignment: Alignment.centerRight,
scale: 0.8,
child: Switch(
thumbIcon: MaterialStateProperty.resolveWith<Icon?>(
@ -98,29 +103,27 @@ class _StyleSettingState extends State<StyleSetting> {
needReboot: true,
),
ListTile(
onTap: () async {
int? result = await showDialog(
context: context,
builder: (context) {
return SelectDialog<int>(title: '自定义列数', value: defaultCustomRows, values: [1, 2, 3, 4, 5].map((e) {
return {'title': '$e', 'value': e};
}).toList());
},
);
if (result != null) {
defaultCustomRows = result;
setting.put(SettingBoxKey.customRows, result);
setState(() {});
}
},
dense: false,
title: Text('自定义列数', style: titleStyle),
subtitle: Text(
'当前列数',
'当前列数 $defaultCustomRows',
style: subTitleStyle,
),
trailing: PopupMenuButton(
initialValue: defaultCustomRows,
icon: const Icon(Icons.more_vert_outlined, size: 22),
onSelected: (item) {
defaultCustomRows = item;
setting.put(SettingBoxKey.customRows, item);
setState(() {});
},
itemBuilder: (BuildContext context) => <PopupMenuEntry>[
for (var i in [1, 2, 3, 4, 5]) ...[
PopupMenuItem(
value: i,
child: Text(i.toString()),
),
]
],
),
),
ListTile(
dense: false,
@ -176,88 +179,58 @@ class _StyleSettingState extends State<StyleSetting> {
},
title: Text('图片质量', style: titleStyle),
subtitle: Text('选择合适的图片清晰度上限100%', style: subTitleStyle),
trailing: Obx(
() => Text(
'${settingController.picQuality.value}%',
style: Theme.of(context).textTheme.titleSmall,
trailing: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Obx(
() => Text(
'${settingController.picQuality.value}%',
style: Theme.of(context).textTheme.titleSmall,
),
),
),
),
ListTile(
dense: false,
onTap: () {
showDialog(
onTap: () async {
ThemeType? result = await showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('主题模式'),
contentPadding: const EdgeInsets.fromLTRB(0, 12, 0, 12),
content: StatefulBuilder(
builder: (context, StateSetter setState) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
for (var i in ThemeType.values) ...[
RadioListTile(
value: i,
title: Text(i.description, style: titleStyle),
groupValue: _tempThemeValue,
onChanged: (ThemeType? value) {
setState(() {
_tempThemeValue = i;
});
},
),
]
],
);
}),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(
'取消',
style: TextStyle(
color: Theme.of(context).colorScheme.outline),
)),
TextButton(
onPressed: () {
settingController.themeType.value = _tempThemeValue;
setting.put(
SettingBoxKey.themeMode, _tempThemeValue.code);
Get.forceAppUpdate();
Get.back();
},
child: const Text('确定'))
],
);
return SelectDialog<ThemeType>(title: '主题模式', value: _tempThemeValue, values: ThemeType.values.map((e) {
return {'title': e.description, 'value': e};
}).toList());
},
);
if (result != null) {
_tempThemeValue = result;
settingController.themeType.value = result;
setting.put(
SettingBoxKey.themeMode, result.code);
Get.forceAppUpdate();
}
},
title: Text('主题模式', style: titleStyle),
subtitle: Obx(() => Text(
'当前模式:${settingController.themeType.value.description}',
style: subTitleStyle)),
trailing: const Icon(Icons.arrow_right_alt_outlined),
),
ListTile(
dense: false,
onTap: () => Get.toNamed('/colorSetting'),
title: Text('应用主题', style: titleStyle),
trailing: const Icon(Icons.arrow_forward_ios, size: 17),
subtitle: Obx(() => Text(
'当前主题:${colorSelectController.type.value == 0 ? '动态取色': '指定颜色'}',
style: subTitleStyle)),
),
ListTile(
dense: false,
onTap: () => Get.toNamed('/fontSizeSetting'),
title: Text('字体大小', style: titleStyle),
trailing: const Icon(Icons.arrow_forward_ios, size: 17),
),
if (Platform.isAndroid)
ListTile(
dense: false,
onTap: () => Get.toNamed('/displayModeSetting'),
title: Text('屏幕帧率', style: titleStyle),
trailing: const Icon(Icons.arrow_forward_ios, size: 17),
)
],
),