2019-09-09 18:50:35 +03:00
|
|
|
part of '../main.dart';
|
2018-11-17 22:40:33 +02:00
|
|
|
|
2020-04-26 00:24:15 +03:00
|
|
|
class UniversalSlider extends StatefulWidget {
|
2018-11-17 22:40:33 +02:00
|
|
|
|
2020-05-05 15:12:49 +03:00
|
|
|
final Function onChanged;
|
|
|
|
final Function onChangeEnd;
|
|
|
|
final Function onChangeStart;
|
2018-11-17 22:40:33 +02:00
|
|
|
final Widget leading;
|
|
|
|
final Widget closing;
|
|
|
|
final String title;
|
|
|
|
final double min;
|
2020-05-05 15:12:49 +03:00
|
|
|
final Color activeColor;
|
2018-11-17 22:40:33 +02:00
|
|
|
final double max;
|
|
|
|
final double value;
|
2020-05-05 15:12:49 +03:00
|
|
|
final int divisions;
|
2019-02-10 17:15:52 +02:00
|
|
|
final EdgeInsets padding;
|
2018-11-17 22:40:33 +02:00
|
|
|
|
2020-05-05 15:12:49 +03:00
|
|
|
const UniversalSlider({Key key, this.onChanged, this.onChangeStart, this.activeColor, this.divisions, this.onChangeEnd, this.leading, this.closing, this.title, this.min, this.max, this.value, this.padding: const EdgeInsets.fromLTRB(Sizes.leftWidgetPadding, Sizes.rowPadding, Sizes.rightWidgetPadding, 0.0)}) : super(key: key);
|
2018-11-17 22:40:33 +02:00
|
|
|
|
2020-04-26 00:24:15 +03:00
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return UniversalSliderState();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class UniversalSliderState extends State<UniversalSlider> {
|
|
|
|
|
|
|
|
double _value;
|
|
|
|
bool _changeStarted = false;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_value = widget.value;
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2018-11-17 22:40:33 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
List <Widget> row = [];
|
2020-05-05 15:12:49 +03:00
|
|
|
List <Widget> col = [];
|
2020-04-26 00:24:15 +03:00
|
|
|
if (widget.leading != null) {
|
|
|
|
row.add(widget.leading);
|
2018-11-17 22:40:33 +02:00
|
|
|
}
|
|
|
|
row.add(
|
2020-04-26 00:24:15 +03:00
|
|
|
Flexible(
|
|
|
|
child: Slider(
|
2020-05-05 14:35:19 +03:00
|
|
|
value: _value ?? math.max(widget.max ?? 100, _value ?? 0),
|
|
|
|
min: widget.min ?? 0,
|
|
|
|
max: widget.max ?? 100,
|
2020-05-05 15:12:49 +03:00
|
|
|
activeColor: widget.activeColor,
|
|
|
|
onChangeStart: (value) {
|
|
|
|
_changeStarted = true;
|
|
|
|
widget.onChangeStart?.call(value);
|
2020-04-26 00:24:15 +03:00
|
|
|
},
|
2020-05-05 15:12:49 +03:00
|
|
|
divisions: widget.divisions,
|
2020-04-26 00:24:15 +03:00
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_value = value;
|
|
|
|
});
|
2020-05-05 15:12:49 +03:00
|
|
|
widget.onChanged?.call(value);
|
2020-04-26 00:24:15 +03:00
|
|
|
},
|
|
|
|
onChangeEnd: (value) {
|
|
|
|
_changeStarted = false;
|
2020-05-05 15:12:49 +03:00
|
|
|
setState(() {
|
|
|
|
_value = value;
|
|
|
|
});
|
2020-04-26 00:24:15 +03:00
|
|
|
Timer(Duration(milliseconds: 500), () {
|
|
|
|
if (!_changeStarted) {
|
2020-05-05 15:12:49 +03:00
|
|
|
widget.onChangeEnd?.call(value);
|
2020-04-26 00:24:15 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
),
|
|
|
|
)
|
2018-11-17 22:40:33 +02:00
|
|
|
);
|
2020-04-26 00:24:15 +03:00
|
|
|
if (widget.closing != null) {
|
|
|
|
row.add(widget.closing);
|
2018-11-17 22:40:33 +02:00
|
|
|
}
|
2020-05-05 15:12:49 +03:00
|
|
|
if (widget.title != null) {
|
|
|
|
col.addAll(<Widget>[
|
|
|
|
Container(height: Sizes.rowPadding,),
|
|
|
|
Text('${widget.title}'),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
col.addAll(<Widget>[
|
|
|
|
Container(height: Sizes.rowPadding,),
|
|
|
|
Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: row,
|
|
|
|
),
|
|
|
|
Container(height: Sizes.rowPadding,)
|
|
|
|
]);
|
2019-02-10 17:15:52 +02:00
|
|
|
return Padding(
|
2020-04-26 00:24:15 +03:00
|
|
|
padding: widget.padding,
|
2019-02-10 17:15:52 +02:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2020-05-05 15:12:49 +03:00
|
|
|
children: col,
|
2019-02-10 17:15:52 +02:00
|
|
|
),
|
2018-11-17 22:40:33 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|