From f5a9a8ad68e07a13e629528af2f87479d0961dcc Mon Sep 17 00:00:00 2001 From: KoolShow <51787949+KoolShow@users.noreply.github.com> Date: Thu, 28 Dec 2023 19:29:56 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89toast=E9=80=8F?= =?UTF-8?q?=E6=98=8E=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/common/widgets/custom_toast.dart | 11 ++++- lib/pages/setting/controller.dart | 3 ++ lib/pages/setting/style_setting.dart | 67 ++++++++++++++++++++++++++++ lib/utils/storage.dart | 1 + 4 files changed, 81 insertions(+), 1 deletion(-) diff --git a/lib/common/widgets/custom_toast.dart b/lib/common/widgets/custom_toast.dart index 9cd3461d..e8ffe23d 100644 --- a/lib/common/widgets/custom_toast.dart +++ b/lib/common/widgets/custom_toast.dart @@ -1,4 +1,8 @@ import 'package:flutter/material.dart'; +import 'package:hive/hive.dart'; +import 'package:pilipala/utils/storage.dart'; + +Box setting = GStrorage.setting; class CustomToast extends StatelessWidget { final String msg; @@ -6,12 +10,17 @@ class CustomToast extends StatelessWidget { @override Widget build(BuildContext context) { + double toastOpacity = + setting.get(SettingBoxKey.defaultToastOp, defaultValue: 0.8); return Container( margin: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom + 30), padding: const EdgeInsets.symmetric(horizontal: 17, vertical: 10), decoration: BoxDecoration( - color: Theme.of(context).colorScheme.primaryContainer, + color: Theme.of(context) + .colorScheme + .primaryContainer + .withOpacity(toastOpacity), borderRadius: BorderRadius.circular(20), ), child: Text( diff --git a/lib/pages/setting/controller.dart b/lib/pages/setting/controller.dart index 0e1505a5..0c3b442f 100644 --- a/lib/pages/setting/controller.dart +++ b/lib/pages/setting/controller.dart @@ -15,6 +15,7 @@ class SettingController extends GetxController { RxBool userLogin = false.obs; RxBool feedBackEnable = false.obs; + RxDouble toastOpacity = (0.8).obs; RxInt picQuality = 10.obs; Rx themeType = ThemeType.system.obs; var userInfo; @@ -26,6 +27,8 @@ class SettingController extends GetxController { userLogin.value = userInfo != null; feedBackEnable.value = setting.get(SettingBoxKey.feedBackEnable, defaultValue: false); + toastOpacity.value = + setting.get(SettingBoxKey.defaultToastOp, defaultValue: 0.8); picQuality.value = setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10); themeType.value = ThemeType.values[setting.get(SettingBoxKey.themeMode, diff --git a/lib/pages/setting/style_setting.dart b/lib/pages/setting/style_setting.dart index 277919dd..a4cc6ac5 100644 --- a/lib/pages/setting/style_setting.dart +++ b/lib/pages/setting/style_setting.dart @@ -24,6 +24,7 @@ class _StyleSettingState extends State { Box setting = GStrorage.setting; late int picQuality; + late double toastOpacity; late ThemeType _tempThemeValue; late dynamic defaultCustomRows; @@ -31,6 +32,7 @@ class _StyleSettingState extends State { void initState() { super.initState(); picQuality = setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10); + toastOpacity = setting.get(SettingBoxKey.defaultToastOp, defaultValue: 0.8); _tempThemeValue = settingController.themeType.value; defaultCustomRows = setting.get(SettingBoxKey.customRows, defaultValue: 2); } @@ -189,6 +191,71 @@ class _StyleSettingState extends State { ), ), ), + ListTile( + dense: false, + onTap: () { + showDialog( + context: context, + builder: (context) { + return StatefulBuilder( + builder: (context, StateSetter setState) { + final SettingController settingController = + Get.put(SettingController()); + return AlertDialog( + title: const Text('Toast不透明度'), + contentPadding: const EdgeInsets.only( + top: 20, left: 8, right: 8, bottom: 8), + content: SizedBox( + height: 40, + child: Slider( + value: toastOpacity, + min: 0.0, + max: 1.0, + divisions: 10, + label: '$toastOpacity%', + onChanged: (double val) { + toastOpacity = val; + setState(() {}); + }, + ), + ), + actions: [ + TextButton( + onPressed: () => Get.back(), + child: Text('取消', + style: TextStyle( + color: Theme.of(context) + .colorScheme + .outline))), + TextButton( + onPressed: () { + setting.put( + SettingBoxKey.defaultToastOp, toastOpacity); + Get.back(); + settingController.toastOpacity.value = + toastOpacity; + }, + child: const Text('确定'), + ) + ], + ); + }, + ); + }, + ); + }, + title: Text('Toast不透明度', style: titleStyle), + subtitle: Text('自定义Toast不透明度', style: subTitleStyle), + trailing: Padding( + padding: const EdgeInsets.symmetric(horizontal: 8.0), + child: Obx( + () => Text( + '${settingController.toastOpacity.value}', + style: Theme.of(context).textTheme.titleSmall, + ), + ), + ), + ), ListTile( dense: false, onTap: () async { diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 44cb162a..e4210636 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -98,6 +98,7 @@ class SettingBoxKey { static const String fullScreenMode = 'fullScreenMode'; static const String defaultDecode = 'defaultDecode'; static const String danmakuEnable = 'danmakuEnable'; + static const String defaultToastOp = 'defaultToastOp'; static const String defaultPicQa = 'defaultPicQa'; static const String enableHA = 'enableHA'; static const String enableOnlineTotal = 'enableOnlineTotal'; From c928037e088b0437607472cc34fa6e47fefd5a30 Mon Sep 17 00:00:00 2001 From: KoolShow <51787949+KoolShow@users.noreply.github.com> Date: Fri, 29 Dec 2023 14:41:06 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9Toast=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E4=B8=8D=E9=80=8F=E6=98=8E=E5=BA=A6=E4=B8=BA1.0,=20=E6=8A=BD?= =?UTF-8?q?=E7=A6=BBslide=5Fdialog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/common/widgets/custom_toast.dart | 2 +- lib/pages/setting/controller.dart | 2 +- lib/pages/setting/style_setting.dart | 62 +++++------------- lib/pages/setting/widgets/slide_dialog.dart | 69 +++++++++++++++++++++ 4 files changed, 86 insertions(+), 49 deletions(-) create mode 100644 lib/pages/setting/widgets/slide_dialog.dart diff --git a/lib/common/widgets/custom_toast.dart b/lib/common/widgets/custom_toast.dart index e8ffe23d..64cf0da2 100644 --- a/lib/common/widgets/custom_toast.dart +++ b/lib/common/widgets/custom_toast.dart @@ -11,7 +11,7 @@ class CustomToast extends StatelessWidget { @override Widget build(BuildContext context) { double toastOpacity = - setting.get(SettingBoxKey.defaultToastOp, defaultValue: 0.8); + setting.get(SettingBoxKey.defaultToastOp, defaultValue: 1.0); return Container( margin: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom + 30), diff --git a/lib/pages/setting/controller.dart b/lib/pages/setting/controller.dart index 0c3b442f..70df6825 100644 --- a/lib/pages/setting/controller.dart +++ b/lib/pages/setting/controller.dart @@ -28,7 +28,7 @@ class SettingController extends GetxController { feedBackEnable.value = setting.get(SettingBoxKey.feedBackEnable, defaultValue: false); toastOpacity.value = - setting.get(SettingBoxKey.defaultToastOp, defaultValue: 0.8); + setting.get(SettingBoxKey.defaultToastOp, defaultValue: 1.0); picQuality.value = setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10); themeType.value = ThemeType.values[setting.get(SettingBoxKey.themeMode, diff --git a/lib/pages/setting/style_setting.dart b/lib/pages/setting/style_setting.dart index a4cc6ac5..23784fac 100644 --- a/lib/pages/setting/style_setting.dart +++ b/lib/pages/setting/style_setting.dart @@ -6,6 +6,7 @@ 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/pages/setting/widgets/slide_dialog.dart'; import 'package:pilipala/utils/storage.dart'; import 'controller.dart'; @@ -32,7 +33,7 @@ class _StyleSettingState extends State { void initState() { super.initState(); picQuality = setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10); - toastOpacity = setting.get(SettingBoxKey.defaultToastOp, defaultValue: 0.8); + toastOpacity = setting.get(SettingBoxKey.defaultToastOp, defaultValue: 1.0); _tempThemeValue = settingController.themeType.value; defaultCustomRows = setting.get(SettingBoxKey.customRows, defaultValue: 2); } @@ -193,56 +194,23 @@ class _StyleSettingState extends State { ), ListTile( dense: false, - onTap: () { - showDialog( + onTap: () async { + double? result = await showDialog( context: context, builder: (context) { - return StatefulBuilder( - builder: (context, StateSetter setState) { - final SettingController settingController = - Get.put(SettingController()); - return AlertDialog( - title: const Text('Toast不透明度'), - contentPadding: const EdgeInsets.only( - top: 20, left: 8, right: 8, bottom: 8), - content: SizedBox( - height: 40, - child: Slider( - value: toastOpacity, - min: 0.0, - max: 1.0, - divisions: 10, - label: '$toastOpacity%', - onChanged: (double val) { - toastOpacity = val; - setState(() {}); - }, - ), - ), - actions: [ - TextButton( - onPressed: () => Get.back(), - child: Text('取消', - style: TextStyle( - color: Theme.of(context) - .colorScheme - .outline))), - TextButton( - onPressed: () { - setting.put( - SettingBoxKey.defaultToastOp, toastOpacity); - Get.back(); - settingController.toastOpacity.value = - toastOpacity; - }, - child: const Text('确定'), - ) - ], - ); - }, - ); + return SlideDialog( + title: 'Toast透明度', + value: toastOpacity, + min: 0.0, + max: 1.0, + divisions: 10); }, ); + if (result != null) { + toastOpacity = result; + setting.put(SettingBoxKey.defaultToastOp, result); + setState(() {}); + } }, title: Text('Toast不透明度', style: titleStyle), subtitle: Text('自定义Toast不透明度', style: subTitleStyle), diff --git a/lib/pages/setting/widgets/slide_dialog.dart b/lib/pages/setting/widgets/slide_dialog.dart new file mode 100644 index 00000000..618f7c51 --- /dev/null +++ b/lib/pages/setting/widgets/slide_dialog.dart @@ -0,0 +1,69 @@ +import 'package:flutter/material.dart'; +// import 'package:pilipala/models/common/theme_type.dart'; + +class SlideDialog extends StatefulWidget { + final T value; + final String title; + final double min; + final double max; + final int divisions; + final String? suffix; + const SlideDialog({ + super.key, + required this.value, + required this.min, + required this.max, + required this.divisions, + required this.title, + this.suffix, + }); + + @override + _SlideDialogState createState() => _SlideDialogState(); +} + +class _SlideDialogState extends State> { + late T _tempValue; + + @override + void initState() { + super.initState(); + _tempValue = widget.value; + } + + @override + Widget build(BuildContext context) { + return AlertDialog( + title: Text(widget.title), + contentPadding: + const EdgeInsets.only(top: 20, left: 8, right: 8, bottom: 8), + content: SizedBox( + height: 40, + child: Slider( + value: widget.value.toDouble(), + min: widget.min, + max: widget.max, + divisions: widget.divisions, + label: '${widget.value}${widget.suffix}', + onChanged: (double value) { + print(value); + setState(() { + _tempValue = value as T; + }); + }, + ), + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context), + child: Text( + '取消', + style: TextStyle(color: Theme.of(context).colorScheme.outline), + )), + TextButton( + onPressed: () => Navigator.pop(context, _tempValue), + child: const Text('确定')) + ], + ); + } +} From 9c301824804cf84fe68905215317778610de1fbc Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 30 Dec 2023 23:30:58 +0800 Subject: [PATCH 3/4] =?UTF-8?q?mod:=20toastOpacity=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC=E3=80=81Slider=E6=BB=91=E5=8A=A8=E6=97=A0=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/setting/controller.dart | 2 +- lib/pages/setting/style_setting.dart | 42 ++++++++++++--------- lib/pages/setting/widgets/slide_dialog.dart | 40 ++++++++++---------- 3 files changed, 47 insertions(+), 37 deletions(-) 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('确定'), + ) ], ); } From 8d42409691089c4fab14e6e168ca892610959ef9 Mon Sep 17 00:00:00 2001 From: KoolShow <51787949+KoolShow@users.noreply.github.com> Date: Tue, 2 Jan 2024 20:55:33 +0800 Subject: [PATCH 4/4] =?UTF-8?q?mod:=20SlideDialog=E6=B3=9B=E5=9E=8B,=20?= =?UTF-8?q?=E5=88=A0=E9=99=A4toastOpacity=E8=AE=BE=E7=BD=AE=E7=9A=84traili?= =?UTF-8?q?ng?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/setting/style_setting.dart | 9 --------- lib/pages/setting/widgets/slide_dialog.dart | 10 +++++----- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/pages/setting/style_setting.dart b/lib/pages/setting/style_setting.dart index c65628c8..586142db 100644 --- a/lib/pages/setting/style_setting.dart +++ b/lib/pages/setting/style_setting.dart @@ -220,15 +220,6 @@ class _StyleSettingState extends State { }, title: Text('Toast不透明度', style: titleStyle), subtitle: Text('自定义Toast不透明度', style: subTitleStyle), - trailing: Padding( - padding: const EdgeInsets.symmetric(horizontal: 8.0), - child: Obx( - () => Text( - '${settingController.toastOpacity.value}', - style: Theme.of(context).textTheme.titleSmall, - ), - ), - ), ), ListTile( dense: false, diff --git a/lib/pages/setting/widgets/slide_dialog.dart b/lib/pages/setting/widgets/slide_dialog.dart index 1224806c..7fa6eeab 100644 --- a/lib/pages/setting/widgets/slide_dialog.dart +++ b/lib/pages/setting/widgets/slide_dialog.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; // import 'package:pilipala/models/common/theme_type.dart'; -class SlideDialog extends StatefulWidget { - final double value; +class SlideDialog extends StatefulWidget { + final T value; final String title; final double min; final double max; @@ -23,13 +23,13 @@ class SlideDialog extends StatefulWidget { _SlideDialogState createState() => _SlideDialogState(); } -class _SlideDialogState extends State> { +class _SlideDialogState extends State> { late double _tempValue; @override void initState() { super.initState(); - _tempValue = widget.value; + _tempValue = widget.value.toDouble(); } @override @@ -62,7 +62,7 @@ class _SlideDialogState extends State> { ), ), TextButton( - onPressed: () => Navigator.pop(context, _tempValue), + onPressed: () => Navigator.pop(context, _tempValue as T), child: const Text('确定'), ) ],