mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-07-29 06:50:12 +08:00
opt: SlideDialog
This commit is contained in:
@@ -5,7 +5,6 @@ import 'package:PiliPlus/common/widgets/color_palette.dart';
|
|||||||
import 'package:PiliPlus/common/widgets/custom_toast.dart';
|
import 'package:PiliPlus/common/widgets/custom_toast.dart';
|
||||||
import 'package:PiliPlus/common/widgets/dialog/dialog.dart';
|
import 'package:PiliPlus/common/widgets/dialog/dialog.dart';
|
||||||
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
||||||
import 'package:PiliPlus/common/widgets/stateful_builder.dart';
|
|
||||||
import 'package:PiliPlus/main.dart';
|
import 'package:PiliPlus/main.dart';
|
||||||
import 'package:PiliPlus/models/common/dynamic/dynamic_badge_mode.dart';
|
import 'package:PiliPlus/models/common/dynamic/dynamic_badge_mode.dart';
|
||||||
import 'package:PiliPlus/models/common/dynamic/up_panel_position.dart';
|
import 'package:PiliPlus/models/common/dynamic/up_panel_position.dart';
|
||||||
@@ -775,109 +774,36 @@ void _showQualityDialog({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const _minUiScale = 0.5;
|
Future<void> _showUiScaleDialog(
|
||||||
const _maxUiScale = 2.0;
|
|
||||||
|
|
||||||
void _showUiScaleDialog(
|
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
VoidCallback setState,
|
VoidCallback setState,
|
||||||
) {
|
) async {
|
||||||
double uiScale = Pref.uiScale;
|
const minUiScale = 0.5;
|
||||||
final textController = TextEditingController(
|
const maxUiScale = 2.0;
|
||||||
text: uiScale.toStringAsFixed(2),
|
|
||||||
);
|
|
||||||
|
|
||||||
showDialog(
|
final result = await showDialog<double>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return AlertDialog(
|
return SlideDialog(
|
||||||
title: const Text('界面缩放'),
|
value: Pref.uiScale,
|
||||||
contentPadding: const EdgeInsets.fromLTRB(24, 20, 24, 12),
|
title: '界面缩放比例',
|
||||||
content: StatefulBuilder(
|
min: minUiScale,
|
||||||
onDispose: textController.dispose,
|
max: maxUiScale,
|
||||||
builder: (context, setDialogState) {
|
divisions: ((maxUiScale - minUiScale) * 20).toInt(),
|
||||||
return Column(
|
precise: 2,
|
||||||
spacing: 20,
|
defVal: 1,
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Slider(
|
|
||||||
padding: .zero,
|
|
||||||
value: uiScale,
|
|
||||||
min: _minUiScale,
|
|
||||||
max: _maxUiScale,
|
|
||||||
secondaryTrackValue: 1.0,
|
|
||||||
divisions: ((_maxUiScale - _minUiScale) * 20).toInt(),
|
|
||||||
label: textController.text,
|
|
||||||
onChanged: (value) => setDialogState(() {
|
|
||||||
uiScale = value.toPrecision(2);
|
|
||||||
textController.text = uiScale.toStringAsFixed(2);
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
TextFormField(
|
|
||||||
controller: textController,
|
|
||||||
keyboardType: const TextInputType.numberWithOptions(
|
|
||||||
decimal: true,
|
|
||||||
),
|
|
||||||
inputFormatters: [
|
|
||||||
LengthLimitingTextInputFormatter(4),
|
|
||||||
FilteringTextInputFormatter.allow(RegExp(r'[\d.]+')),
|
|
||||||
],
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
labelText: '缩放比例',
|
|
||||||
hintText: '0.50 - 2.00',
|
|
||||||
border: OutlineInputBorder(),
|
|
||||||
),
|
|
||||||
onChanged: (value) {
|
|
||||||
final parsed = double.tryParse(value);
|
|
||||||
if (parsed != null &&
|
|
||||||
parsed >= _minUiScale &&
|
|
||||||
parsed <= _maxUiScale) {
|
|
||||||
setDialogState(() {
|
|
||||||
uiScale = parsed;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
Pref.uiScale = 1.0;
|
|
||||||
GStorage.setting.delete(SettingBoxKey.uiScale).whenComplete(() {
|
|
||||||
setState();
|
|
||||||
Get.appUpdate();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: const Text('重置'),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
child: Text(
|
|
||||||
'取消',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Theme.of(context).colorScheme.outline,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
Pref.uiScale = uiScale;
|
|
||||||
GStorage.setting.put(SettingBoxKey.uiScale, uiScale).whenComplete(
|
|
||||||
() {
|
|
||||||
setState();
|
|
||||||
Get.appUpdate();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: const Text('确定'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (result != null) {
|
||||||
|
if (result.isNaN) {
|
||||||
|
Pref.uiScale = 1.0;
|
||||||
|
await GStorage.setting.delete(SettingBoxKey.uiScale);
|
||||||
|
} else {
|
||||||
|
Pref.uiScale = result;
|
||||||
|
await GStorage.setting.put(SettingBoxKey.uiScale, result);
|
||||||
|
}
|
||||||
|
Get.appUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import 'package:PiliPlus/utils/extension/num_ext.dart';
|
import 'package:PiliPlus/utils/extension/num_ext.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
class SlideDialog extends StatefulWidget {
|
class SlideDialog extends StatefulWidget {
|
||||||
final double value;
|
final double value;
|
||||||
@@ -7,8 +9,9 @@ class SlideDialog extends StatefulWidget {
|
|||||||
final double min;
|
final double min;
|
||||||
final double max;
|
final double max;
|
||||||
final int? divisions;
|
final int? divisions;
|
||||||
final String suffix;
|
final String? suffix;
|
||||||
final int precise;
|
final int precise;
|
||||||
|
final double? defVal;
|
||||||
|
|
||||||
const SlideDialog({
|
const SlideDialog({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -17,8 +20,9 @@ class SlideDialog extends StatefulWidget {
|
|||||||
required this.min,
|
required this.min,
|
||||||
required this.max,
|
required this.max,
|
||||||
this.divisions,
|
this.divisions,
|
||||||
this.suffix = '',
|
this.suffix,
|
||||||
this.precise = 1,
|
this.precise = 1,
|
||||||
|
this.defVal,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -27,49 +31,100 @@ class SlideDialog extends StatefulWidget {
|
|||||||
|
|
||||||
class _SlideDialogState extends State<SlideDialog> {
|
class _SlideDialogState extends State<SlideDialog> {
|
||||||
late double _tempValue;
|
late double _tempValue;
|
||||||
|
late final TextEditingController _controller;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_tempValue = widget.value;
|
_tempValue = widget.value;
|
||||||
|
_controller = TextEditingController(
|
||||||
|
text: _tempValue.toStringAsFixed(widget.precise),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_controller.dispose();
|
||||||
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final colorScheme = ColorScheme.of(context);
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: Text(widget.title),
|
title: Text(widget.title),
|
||||||
contentPadding: const EdgeInsets.only(
|
contentPadding: const .only(top: 24, left: 20, right: 20, bottom: 12),
|
||||||
top: 20,
|
content: Column(
|
||||||
left: 8,
|
mainAxisSize: .min,
|
||||||
right: 8,
|
spacing: 20,
|
||||||
bottom: 8,
|
children: [
|
||||||
),
|
Slider(
|
||||||
content: SizedBox(
|
padding: .zero,
|
||||||
height: 40,
|
value: _tempValue,
|
||||||
child: Slider(
|
min: widget.min,
|
||||||
value: _tempValue,
|
max: widget.max,
|
||||||
min: widget.min,
|
divisions: widget.divisions,
|
||||||
max: widget.max,
|
secondaryTrackValue: widget.defVal,
|
||||||
divisions: widget.divisions,
|
label:
|
||||||
label:
|
'${_tempValue.toStringAsFixed(widget.precise)}${widget.suffix ?? ""}',
|
||||||
'${_tempValue.toStringAsFixed(widget.precise)}${widget.suffix}',
|
onChanged: (value) => setState(() {
|
||||||
onChanged: (double value) {
|
|
||||||
setState(() {
|
|
||||||
_tempValue = value.toPrecision(widget.precise);
|
_tempValue = value.toPrecision(widget.precise);
|
||||||
});
|
_controller.text = _tempValue.toStringAsFixed(widget.precise);
|
||||||
},
|
}),
|
||||||
),
|
),
|
||||||
|
TextField(
|
||||||
|
controller: _controller,
|
||||||
|
maxLines: 1,
|
||||||
|
keyboardType: const .numberWithOptions(decimal: true),
|
||||||
|
inputFormatters: [
|
||||||
|
FilteringTextInputFormatter.allow(RegExp(r'[\d.]+')),
|
||||||
|
],
|
||||||
|
decoration: InputDecoration(
|
||||||
|
suffixText: widget.suffix,
|
||||||
|
labelText: widget.title,
|
||||||
|
hintText:
|
||||||
|
'${widget.min.toStringAsFixed(widget.precise)} - ${widget.max.toStringAsFixed(widget.precise)}',
|
||||||
|
border: const OutlineInputBorder(),
|
||||||
|
),
|
||||||
|
onChanged: (value) {
|
||||||
|
final parsed = double.tryParse(value);
|
||||||
|
if (parsed != null &&
|
||||||
|
widget.min <= parsed &&
|
||||||
|
parsed <= widget.max) {
|
||||||
|
setState(() {
|
||||||
|
_tempValue = parsed.toPrecision(widget.precise);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onSubmitted: (value) {
|
||||||
|
final parsed = double.tryParse(value);
|
||||||
|
if (parsed != null) {
|
||||||
|
setState(() {
|
||||||
|
_tempValue = parsed
|
||||||
|
.clamp(widget.min, widget.max)
|
||||||
|
.toPrecision(widget.precise);
|
||||||
|
_controller.text = _tempValue.toStringAsFixed(widget.precise);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
|
if (widget.defVal != null)
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Get.back(result: double.nan),
|
||||||
|
child: Text('重置', style: TextStyle(color: colorScheme.error)),
|
||||||
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: Navigator.of(context).pop,
|
onPressed: Get.back,
|
||||||
child: Text(
|
child: Text(
|
||||||
'取消',
|
'取消',
|
||||||
style: TextStyle(color: Theme.of(context).colorScheme.outline),
|
style: TextStyle(color: colorScheme.outline),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.pop(context, _tempValue),
|
onPressed: () => Get.back(result: _tempValue),
|
||||||
child: const Text('确定'),
|
child: const Text('确定'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user