mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-21 19:28:27 +08:00
78
lib/pages/setting/widgets/slider_dialog.dart
Normal file
78
lib/pages/setting/widgets/slider_dialog.dart
Normal file
@@ -0,0 +1,78 @@
|
||||
import 'package:PiliPlus/utils/extension/num_ext.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SliderDialog extends StatefulWidget {
|
||||
final double value;
|
||||
final String title;
|
||||
final double min;
|
||||
final double max;
|
||||
final int? divisions;
|
||||
final String suffix;
|
||||
final int precise;
|
||||
|
||||
const SliderDialog({
|
||||
super.key,
|
||||
required this.value,
|
||||
required this.title,
|
||||
required this.min,
|
||||
required this.max,
|
||||
this.divisions,
|
||||
this.suffix = '',
|
||||
this.precise = 1,
|
||||
});
|
||||
|
||||
@override
|
||||
State<SliderDialog> createState() => _SliderDialogState();
|
||||
}
|
||||
|
||||
class _SliderDialogState extends State<SliderDialog> {
|
||||
late double _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: _tempValue,
|
||||
min: widget.min,
|
||||
max: widget.max,
|
||||
divisions: widget.divisions,
|
||||
label:
|
||||
'${_tempValue.toStringAsFixed(widget.precise)}${widget.suffix}',
|
||||
onChanged: (double value) {
|
||||
setState(() {
|
||||
_tempValue = value.toPrecision(widget.precise);
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: Navigator.of(context).pop,
|
||||
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