diff --git a/lib/widgets/duration_picker.dart b/lib/widgets/duration_picker.dart index 0f4265f..469a15f 100644 --- a/lib/widgets/duration_picker.dart +++ b/lib/widgets/duration_picker.dart @@ -6,11 +6,13 @@ class DurationPicker extends StatefulWidget { required this.onChangedCallback, required this.width, required this.height, + this.initialDuration = const Duration(), }); final void Function(Duration duration) onChangedCallback; final double width; final double height; + final Duration initialDuration; @override State createState() => _DurationPickerState(); @@ -19,6 +21,15 @@ class DurationPicker extends StatefulWidget { class _DurationPickerState extends State { String _timeString = ''; + @override + void initState() { + super.initState(); + if (widget.initialDuration.inMinutes != 0) { + _timeString = + '${widget.initialDuration.inHours}${widget.initialDuration.inMinutes % 60}'; + } + } + @override Widget build(BuildContext context) { return Column( @@ -69,7 +80,7 @@ class _DurationPickerState extends State { child: ElevatedButton( style: _buttonTheme, onPressed: () => _addTime(7), - child: _getTextWidget('7'), + child: Text('7'), ), ), ), @@ -81,7 +92,7 @@ class _DurationPickerState extends State { child: ElevatedButton( style: _buttonTheme, onPressed: () => _addTime(8), - child: _getTextWidget('8'), + child: Text('8'), ), ), ), @@ -93,7 +104,7 @@ class _DurationPickerState extends State { child: ElevatedButton( style: _buttonTheme, onPressed: () => _addTime(9), - child: _getTextWidget('9'), + child: Text('9'), ), ), ), @@ -111,7 +122,7 @@ class _DurationPickerState extends State { child: ElevatedButton( style: _buttonTheme, onPressed: () => _addTime(4), - child: _getTextWidget('4'), + child: Text('4'), ), ), ), @@ -123,7 +134,7 @@ class _DurationPickerState extends State { child: ElevatedButton( style: _buttonTheme, onPressed: () => _addTime(5), - child: _getTextWidget('5'), + child: Text('5'), ), ), ), @@ -135,7 +146,7 @@ class _DurationPickerState extends State { child: ElevatedButton( style: _buttonTheme, onPressed: () => _addTime(6), - child: _getTextWidget('6'), + child: Text('6'), ), ), ), @@ -153,7 +164,7 @@ class _DurationPickerState extends State { child: ElevatedButton( style: _buttonTheme, onPressed: () => _addTime(1), - child: _getTextWidget('1'), + child: Text('1'), ), ), ), @@ -165,7 +176,7 @@ class _DurationPickerState extends State { child: ElevatedButton( style: _buttonTheme, onPressed: () => _addTime(2), - child: _getTextWidget('2'), + child: Text('2'), ), ), ), @@ -177,7 +188,7 @@ class _DurationPickerState extends State { child: ElevatedButton( style: _buttonTheme, onPressed: () => _addTime(3), - child: _getTextWidget('3'), + child: Text('3'), ), ), ), @@ -200,7 +211,7 @@ class _DurationPickerState extends State { child: ElevatedButton( style: _buttonTheme, onPressed: () => _addTime(0), - child: _getTextWidget('0'), + child: Text('0'), ), ), ), @@ -225,10 +236,6 @@ class _DurationPickerState extends State { ); } - Text _getTextWidget(String text) { - return Text(text); - } - void _addTime(int time) { if (_timeString.length >= 4) return; if (_timeString.isEmpty && time == 0) return;