修改Toast默认不透明度为1.0, 抽离slide_dialog
This commit is contained in:
@ -11,7 +11,7 @@ class CustomToast extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
double toastOpacity =
|
double toastOpacity =
|
||||||
setting.get(SettingBoxKey.defaultToastOp, defaultValue: 0.8);
|
setting.get(SettingBoxKey.defaultToastOp, defaultValue: 1.0);
|
||||||
return Container(
|
return Container(
|
||||||
margin:
|
margin:
|
||||||
EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom + 30),
|
EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom + 30),
|
||||||
|
|||||||
@ -28,7 +28,7 @@ class SettingController extends GetxController {
|
|||||||
feedBackEnable.value =
|
feedBackEnable.value =
|
||||||
setting.get(SettingBoxKey.feedBackEnable, defaultValue: false);
|
setting.get(SettingBoxKey.feedBackEnable, defaultValue: false);
|
||||||
toastOpacity.value =
|
toastOpacity.value =
|
||||||
setting.get(SettingBoxKey.defaultToastOp, defaultValue: 0.8);
|
setting.get(SettingBoxKey.defaultToastOp, defaultValue: 1.0);
|
||||||
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,
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import 'package:hive/hive.dart';
|
|||||||
import 'package:pilipala/models/common/theme_type.dart';
|
import 'package:pilipala/models/common/theme_type.dart';
|
||||||
import 'package:pilipala/pages/setting/pages/color_select.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/select_dialog.dart';
|
||||||
|
import 'package:pilipala/pages/setting/widgets/slide_dialog.dart';
|
||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
|
||||||
import 'controller.dart';
|
import 'controller.dart';
|
||||||
@ -32,7 +33,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);
|
toastOpacity = setting.get(SettingBoxKey.defaultToastOp, defaultValue: 1.0);
|
||||||
_tempThemeValue = settingController.themeType.value;
|
_tempThemeValue = settingController.themeType.value;
|
||||||
defaultCustomRows = setting.get(SettingBoxKey.customRows, defaultValue: 2);
|
defaultCustomRows = setting.get(SettingBoxKey.customRows, defaultValue: 2);
|
||||||
}
|
}
|
||||||
@ -193,56 +194,23 @@ class _StyleSettingState extends State<StyleSetting> {
|
|||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
dense: false,
|
dense: false,
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
showDialog(
|
double? result = await showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return StatefulBuilder(
|
return SlideDialog<double>(
|
||||||
builder: (context, StateSetter setState) {
|
title: 'Toast透明度',
|
||||||
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,
|
value: toastOpacity,
|
||||||
min: 0.0,
|
min: 0.0,
|
||||||
max: 1.0,
|
max: 1.0,
|
||||||
divisions: 10,
|
divisions: 10);
|
||||||
label: '$toastOpacity%',
|
},
|
||||||
onChanged: (double val) {
|
);
|
||||||
toastOpacity = val;
|
if (result != null) {
|
||||||
|
toastOpacity = result;
|
||||||
|
setting.put(SettingBoxKey.defaultToastOp, result);
|
||||||
setState(() {});
|
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),
|
title: Text('Toast不透明度', style: titleStyle),
|
||||||
subtitle: Text('自定义Toast不透明度', style: subTitleStyle),
|
subtitle: Text('自定义Toast不透明度', style: subTitleStyle),
|
||||||
|
|||||||
69
lib/pages/setting/widgets/slide_dialog.dart
Normal file
69
lib/pages/setting/widgets/slide_dialog.dart
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
// import 'package:pilipala/models/common/theme_type.dart';
|
||||||
|
|
||||||
|
class SlideDialog<T extends num> 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<T> createState() => _SlideDialogState<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SlideDialogState<T extends num> extends State<SlideDialog<T>> {
|
||||||
|
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('确定'))
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user