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 feedBackEnable = false.obs;
RxDouble toastOpacity = (0.8).obs;
RxDouble toastOpacity = (1.0).obs;
RxInt picQuality = 10.obs;
Rx<ThemeType> themeType = ThemeType.system.obs;
var userInfo;

View File

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

View File

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