自定义toast透明度

This commit is contained in:
KoolShow
2023-12-28 19:29:56 +08:00
parent 7feb462ea5
commit f5a9a8ad68
4 changed files with 81 additions and 1 deletions

View File

@ -1,4 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:pilipala/utils/storage.dart';
Box setting = GStrorage.setting;
class CustomToast extends StatelessWidget { class CustomToast extends StatelessWidget {
final String msg; final String msg;
@ -6,12 +10,17 @@ class CustomToast extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
double toastOpacity =
setting.get(SettingBoxKey.defaultToastOp, defaultValue: 0.8);
return Container( return Container(
margin: margin:
EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom + 30), EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom + 30),
padding: const EdgeInsets.symmetric(horizontal: 17, vertical: 10), padding: const EdgeInsets.symmetric(horizontal: 17, vertical: 10),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primaryContainer, color: Theme.of(context)
.colorScheme
.primaryContainer
.withOpacity(toastOpacity),
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
), ),
child: Text( child: Text(

View File

@ -15,6 +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;
RxInt picQuality = 10.obs; RxInt picQuality = 10.obs;
Rx<ThemeType> themeType = ThemeType.system.obs; Rx<ThemeType> themeType = ThemeType.system.obs;
var userInfo; var userInfo;
@ -26,6 +27,8 @@ class SettingController extends GetxController {
userLogin.value = userInfo != null; userLogin.value = userInfo != null;
feedBackEnable.value = feedBackEnable.value =
setting.get(SettingBoxKey.feedBackEnable, defaultValue: false); setting.get(SettingBoxKey.feedBackEnable, defaultValue: false);
toastOpacity.value =
setting.get(SettingBoxKey.defaultToastOp, defaultValue: 0.8);
picQuality.value = picQuality.value =
setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10); setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10);
themeType.value = ThemeType.values[setting.get(SettingBoxKey.themeMode, themeType.value = ThemeType.values[setting.get(SettingBoxKey.themeMode,

View File

@ -24,6 +24,7 @@ class _StyleSettingState extends State<StyleSetting> {
Box setting = GStrorage.setting; Box setting = GStrorage.setting;
late int picQuality; late int picQuality;
late double toastOpacity;
late ThemeType _tempThemeValue; late ThemeType _tempThemeValue;
late dynamic defaultCustomRows; late dynamic defaultCustomRows;
@ -31,6 +32,7 @@ class _StyleSettingState extends State<StyleSetting> {
void initState() { void initState() {
super.initState(); super.initState();
picQuality = setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10); picQuality = setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10);
toastOpacity = setting.get(SettingBoxKey.defaultToastOp, defaultValue: 0.8);
_tempThemeValue = settingController.themeType.value; _tempThemeValue = settingController.themeType.value;
defaultCustomRows = setting.get(SettingBoxKey.customRows, defaultValue: 2); defaultCustomRows = setting.get(SettingBoxKey.customRows, defaultValue: 2);
} }
@ -189,6 +191,71 @@ class _StyleSettingState extends State<StyleSetting> {
), ),
), ),
), ),
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( ListTile(
dense: false, dense: false,
onTap: () async { onTap: () async {

View File

@ -98,6 +98,7 @@ class SettingBoxKey {
static const String fullScreenMode = 'fullScreenMode'; static const String fullScreenMode = 'fullScreenMode';
static const String defaultDecode = 'defaultDecode'; static const String defaultDecode = 'defaultDecode';
static const String danmakuEnable = 'danmakuEnable'; static const String danmakuEnable = 'danmakuEnable';
static const String defaultToastOp = 'defaultToastOp';
static const String defaultPicQa = 'defaultPicQa'; static const String defaultPicQa = 'defaultPicQa';
static const String enableHA = 'enableHA'; static const String enableHA = 'enableHA';
static const String enableOnlineTotal = 'enableOnlineTotal'; static const String enableOnlineTotal = 'enableOnlineTotal';