cleaned up widget and added initialDuration field
This commit is contained in:
@@ -6,11 +6,13 @@ class DurationPicker extends StatefulWidget {
|
|||||||
required this.onChangedCallback,
|
required this.onChangedCallback,
|
||||||
required this.width,
|
required this.width,
|
||||||
required this.height,
|
required this.height,
|
||||||
|
this.initialDuration = const Duration(),
|
||||||
});
|
});
|
||||||
|
|
||||||
final void Function(Duration duration) onChangedCallback;
|
final void Function(Duration duration) onChangedCallback;
|
||||||
final double width;
|
final double width;
|
||||||
final double height;
|
final double height;
|
||||||
|
final Duration initialDuration;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<DurationPicker> createState() => _DurationPickerState();
|
State<DurationPicker> createState() => _DurationPickerState();
|
||||||
@@ -19,6 +21,15 @@ class DurationPicker extends StatefulWidget {
|
|||||||
class _DurationPickerState extends State<DurationPicker> {
|
class _DurationPickerState extends State<DurationPicker> {
|
||||||
String _timeString = '';
|
String _timeString = '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
if (widget.initialDuration.inMinutes != 0) {
|
||||||
|
_timeString =
|
||||||
|
'${widget.initialDuration.inHours}${widget.initialDuration.inMinutes % 60}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
return Column(
|
||||||
@@ -69,7 +80,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(7),
|
onPressed: () => _addTime(7),
|
||||||
child: _getTextWidget('7'),
|
child: Text('7'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -81,7 +92,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(8),
|
onPressed: () => _addTime(8),
|
||||||
child: _getTextWidget('8'),
|
child: Text('8'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -93,7 +104,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(9),
|
onPressed: () => _addTime(9),
|
||||||
child: _getTextWidget('9'),
|
child: Text('9'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -111,7 +122,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(4),
|
onPressed: () => _addTime(4),
|
||||||
child: _getTextWidget('4'),
|
child: Text('4'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -123,7 +134,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(5),
|
onPressed: () => _addTime(5),
|
||||||
child: _getTextWidget('5'),
|
child: Text('5'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -135,7 +146,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(6),
|
onPressed: () => _addTime(6),
|
||||||
child: _getTextWidget('6'),
|
child: Text('6'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -153,7 +164,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(1),
|
onPressed: () => _addTime(1),
|
||||||
child: _getTextWidget('1'),
|
child: Text('1'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -165,7 +176,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(2),
|
onPressed: () => _addTime(2),
|
||||||
child: _getTextWidget('2'),
|
child: Text('2'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -177,7 +188,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(3),
|
onPressed: () => _addTime(3),
|
||||||
child: _getTextWidget('3'),
|
child: Text('3'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -200,7 +211,7 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: _buttonTheme,
|
style: _buttonTheme,
|
||||||
onPressed: () => _addTime(0),
|
onPressed: () => _addTime(0),
|
||||||
child: _getTextWidget('0'),
|
child: Text('0'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -225,10 +236,6 @@ class _DurationPickerState extends State<DurationPicker> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Text _getTextWidget(String text) {
|
|
||||||
return Text(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _addTime(int time) {
|
void _addTime(int time) {
|
||||||
if (_timeString.length >= 4) return;
|
if (_timeString.length >= 4) return;
|
||||||
if (_timeString.isEmpty && time == 0) return;
|
if (_timeString.isEmpty && time == 0) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user