From 603b409719e18310915168255097090070053c46 Mon Sep 17 00:00:00 2001 From: KoolShow <51787949+KoolShow@users.noreply.github.com> Date: Thu, 28 Dec 2023 19:32:39 +0800 Subject: [PATCH] Feature (#12) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修改toast为半透明 * 自定义toast透明度 --- lib/common/widgets/custom_toast.dart | 12 ++++- lib/pages/setting/controller.dart | 3 ++ lib/pages/setting/style_setting.dart | 67 ++++++++++++++++++++++++++++ lib/utils/storage.dart | 1 + 4 files changed, 82 insertions(+), 1 deletion(-) diff --git a/lib/common/widgets/custom_toast.dart b/lib/common/widgets/custom_toast.dart index d31cc3702..c82b6d57e 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,18 @@ 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.withOpacity(0.8), + 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 0e1505a5a..0c3b442f2 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 277919ddf..a4cc6ac58 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 44cb162a4..e42106367 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';