mod: toastOpacity默认值、Slider滑动无效

This commit is contained in:
guozhigq
2023-12-30 23:30:58 +08:00
parent c928037e08
commit 9c30182480
3 changed files with 47 additions and 37 deletions

View File

@ -15,7 +15,7 @@ class SettingController extends GetxController {
RxBool userLogin = false.obs; RxBool userLogin = false.obs;
RxBool feedBackEnable = false.obs; RxBool feedBackEnable = false.obs;
RxDouble toastOpacity = (0.8).obs; RxDouble toastOpacity = (1.0).obs;
RxInt picQuality = 10.obs; RxInt picQuality = 10.obs;
Rx<ThemeType> themeType = ThemeType.system.obs; Rx<ThemeType> themeType = ThemeType.system.obs;
var userInfo; var userInfo;

View File

@ -1,6 +1,7 @@
import 'dart:io'; import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:pilipala/models/common/theme_type.dart'; import 'package:pilipala/models/common/theme_type.dart';
@ -21,7 +22,8 @@ class StyleSetting extends StatefulWidget {
class _StyleSettingState extends State<StyleSetting> { class _StyleSettingState extends State<StyleSetting> {
final SettingController settingController = Get.put(SettingController()); final SettingController settingController = Get.put(SettingController());
final ColorSelectController colorSelectController = Get.put(ColorSelectController()); final ColorSelectController colorSelectController =
Get.put(ColorSelectController());
Box setting = GStrorage.setting; Box setting = GStrorage.setting;
late int picQuality; late int picQuality;
@ -110,9 +112,12 @@ class _StyleSettingState extends State<StyleSetting> {
int? result = await showDialog( int? result = await showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return SelectDialog<int>(title: '自定义列数', value: defaultCustomRows, values: [1, 2, 3, 4, 5].map((e) { return SelectDialog<int>(
return {'title': '$e', 'value': e}; title: '自定义列数',
}).toList()); value: defaultCustomRows,
values: [1, 2, 3, 4, 5].map((e) {
return {'title': '$e', 'value': e};
}).toList());
}, },
); );
if (result != null) { if (result != null) {
@ -199,17 +204,18 @@ class _StyleSettingState extends State<StyleSetting> {
context: context, context: context,
builder: (context) { builder: (context) {
return SlideDialog<double>( return SlideDialog<double>(
title: 'Toast透明度', title: 'Toast透明度',
value: toastOpacity, value: settingController.toastOpacity.value,
min: 0.0, min: 0.0,
max: 1.0, max: 1.0,
divisions: 10); divisions: 10,
);
}, },
); );
if (result != null) { if (result != null) {
toastOpacity = result; settingController.toastOpacity.value = result;
SmartDialog.showToast('设置成功');
setting.put(SettingBoxKey.defaultToastOp, result); setting.put(SettingBoxKey.defaultToastOp, result);
setState(() {});
} }
}, },
title: Text('Toast不透明度', style: titleStyle), title: Text('Toast不透明度', style: titleStyle),
@ -230,16 +236,18 @@ class _StyleSettingState extends State<StyleSetting> {
ThemeType? result = await showDialog( ThemeType? result = await showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return SelectDialog<ThemeType>(title: '主题模式', value: _tempThemeValue, values: ThemeType.values.map((e) { return SelectDialog<ThemeType>(
return {'title': e.description, 'value': e}; title: '主题模式',
}).toList()); value: _tempThemeValue,
values: ThemeType.values.map((e) {
return {'title': e.description, 'value': e};
}).toList());
}, },
); );
if (result != null) { if (result != null) {
_tempThemeValue = result; _tempThemeValue = result;
settingController.themeType.value = result; settingController.themeType.value = result;
setting.put( setting.put(SettingBoxKey.themeMode, result.code);
SettingBoxKey.themeMode, result.code);
Get.forceAppUpdate(); Get.forceAppUpdate();
} }
}, },
@ -253,7 +261,7 @@ class _StyleSettingState extends State<StyleSetting> {
onTap: () => Get.toNamed('/colorSetting'), onTap: () => Get.toNamed('/colorSetting'),
title: Text('应用主题', style: titleStyle), title: Text('应用主题', style: titleStyle),
subtitle: Obx(() => Text( subtitle: Obx(() => Text(
'当前主题:${colorSelectController.type.value == 0 ? '动态取色': '指定颜色'}', '当前主题:${colorSelectController.type.value == 0 ? '动态取色' : '指定颜色'}',
style: subTitleStyle)), style: subTitleStyle)),
), ),
ListTile( ListTile(

View File

@ -1,20 +1,21 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
// import 'package:pilipala/models/common/theme_type.dart'; // import 'package:pilipala/models/common/theme_type.dart';
class SlideDialog<T extends num> extends StatefulWidget { class SlideDialog<T extends double> extends StatefulWidget {
final T value; final double value;
final String title; final String title;
final double min; final double min;
final double max; final double max;
final int divisions; final int? divisions;
final String? suffix; final String? suffix;
const SlideDialog({ const SlideDialog({
super.key, super.key,
required this.value, required this.value,
required this.title,
required this.min, required this.min,
required this.max, required this.max,
required this.divisions, this.divisions,
required this.title,
this.suffix, this.suffix,
}); });
@ -22,8 +23,8 @@ class SlideDialog<T extends num> extends StatefulWidget {
_SlideDialogState<T> createState() => _SlideDialogState<T>(); _SlideDialogState<T> createState() => _SlideDialogState<T>();
} }
class _SlideDialogState<T extends num> extends State<SlideDialog<T>> { class _SlideDialogState<T extends double> extends State<SlideDialog<T>> {
late T _tempValue; late double _tempValue;
@override @override
void initState() { void initState() {
@ -40,29 +41,30 @@ class _SlideDialogState<T extends num> extends State<SlideDialog<T>> {
content: SizedBox( content: SizedBox(
height: 40, height: 40,
child: Slider( child: Slider(
value: widget.value.toDouble(), value: _tempValue,
min: widget.min, min: widget.min,
max: widget.max, max: widget.max,
divisions: widget.divisions, divisions: widget.divisions ?? 10,
label: '${widget.value}${widget.suffix}', label: '$_tempValue${widget.suffix ?? ''}',
onChanged: (double value) { onChanged: (double value) {
print(value);
setState(() { setState(() {
_tempValue = value as T; _tempValue = value;
}); });
}, },
), ),
), ),
actions: [ actions: [
TextButton( TextButton(
onPressed: () => Navigator.pop(context), onPressed: () => Navigator.pop(context),
child: Text( child: Text(
'取消', '取消',
style: TextStyle(color: Theme.of(context).colorScheme.outline), style: TextStyle(color: Theme.of(context).colorScheme.outline),
)), ),
),
TextButton( TextButton(
onPressed: () => Navigator.pop(context, _tempValue), onPressed: () => Navigator.pop(context, _tempValue),
child: const Text('确定')) child: const Text('确定'),
)
], ],
); );
} }