Skip to content

Commit

Permalink
Feature (#12)
Browse files Browse the repository at this point in the history
* 修改toast为半透明

* 自定义toast透明度
  • Loading branch information
KoolShow authored Dec 28, 2023
1 parent 317eb0d commit 603b409
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/common/widgets/custom_toast.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
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;
const CustomToast({Key? key, required this.msg}) : super(key: key);

@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(
Expand Down
3 changes: 3 additions & 0 deletions lib/pages/setting/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ThemeType.system.obs;
var userInfo;
Expand All @@ -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,
Expand Down
67 changes: 67 additions & 0 deletions lib/pages/setting/style_setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ class _StyleSettingState extends State<StyleSetting> {

Box setting = GStrorage.setting;
late int picQuality;
late double toastOpacity;
late ThemeType _tempThemeValue;
late dynamic defaultCustomRows;

@override
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);
}
Expand Down Expand Up @@ -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(
dense: false,
onTap: () async {
Expand Down
1 change: 1 addition & 0 deletions lib/utils/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 603b409

Please sign in to comment.