diff --git a/lib/pages/setting/controller.dart b/lib/pages/setting/controller.dart index 70df6825..afd14156 100644 --- a/lib/pages/setting/controller.dart +++ b/lib/pages/setting/controller.dart @@ -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.system.obs; var userInfo; diff --git a/lib/pages/setting/style_setting.dart b/lib/pages/setting/style_setting.dart index 23784fac..c65628c8 100644 --- a/lib/pages/setting/style_setting.dart +++ b/lib/pages/setting/style_setting.dart @@ -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 { 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 { int? result = await showDialog( context: context, builder: (context) { - return SelectDialog(title: '自定义列数', value: defaultCustomRows, values: [1, 2, 3, 4, 5].map((e) { - return {'title': '$e 列', 'value': e}; - }).toList()); + return SelectDialog( + 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 { context: context, builder: (context) { return SlideDialog( - 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 { ThemeType? result = await showDialog( context: context, builder: (context) { - return SelectDialog(title: '主题模式', value: _tempThemeValue, values: ThemeType.values.map((e) { - return {'title': e.description, 'value': e}; - }).toList()); + return SelectDialog( + 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 { onTap: () => Get.toNamed('/colorSetting'), title: Text('应用主题', style: titleStyle), subtitle: Obx(() => Text( - '当前主题:${colorSelectController.type.value == 0 ? '动态取色': '指定颜色'}', + '当前主题:${colorSelectController.type.value == 0 ? '动态取色' : '指定颜色'}', style: subTitleStyle)), ), ListTile( diff --git a/lib/pages/setting/widgets/slide_dialog.dart b/lib/pages/setting/widgets/slide_dialog.dart index 618f7c51..1224806c 100644 --- a/lib/pages/setting/widgets/slide_dialog.dart +++ b/lib/pages/setting/widgets/slide_dialog.dart @@ -1,20 +1,21 @@ import 'package:flutter/material.dart'; // import 'package:pilipala/models/common/theme_type.dart'; -class SlideDialog extends StatefulWidget { - final T value; +class SlideDialog 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 extends StatefulWidget { _SlideDialogState createState() => _SlideDialogState(); } -class _SlideDialogState extends State> { - late T _tempValue; +class _SlideDialogState extends State> { + late double _tempValue; @override void initState() { @@ -40,29 +41,30 @@ class _SlideDialogState extends State> { 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('确定'), + ) ], ); }