From 549af835726add0023084e4440438306fa005af9 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 10 Feb 2020 14:30:37 -0600 Subject: [PATCH 1/2] if no duration selected, do not allow save and show error --- lib/pages/new_task_page.dart | 48 +++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/lib/pages/new_task_page.dart b/lib/pages/new_task_page.dart index 0db30f7..c8c6ab6 100644 --- a/lib/pages/new_task_page.dart +++ b/lib/pages/new_task_page.dart @@ -21,26 +21,32 @@ class _NewTaskPageState extends State { int _selectedHour = 0; int _selectedMinute = 0; int _selectedSecond = 0; + String _durationError = ''; Color getRandomColor() { Random r = Random(); var colorsList = Colors.primaries; - return colorsList.elementAt(r.nextInt(colorsList.length -1)); + return colorsList.elementAt(r.nextInt(colorsList.length - 1)); } - void _saveTaskAndClose() { + void _saveTaskAndClose() { String title = _titleController.text; if (_formKey.currentState.validate() != false) { + if (_selectedHour == 0 && _selectedMinute == 0 && _selectedSecond == 0) { + setState(() => + _durationError = 'Select a duration by swiping an interval up'); + return; + } + _durationError = ''; var color = getRandomColor(); var task = new Task( - color: color, - title: title, - hours: _selectedHour, - minutes: _selectedMinute, - seconds: _selectedSecond - ); + color: color, + title: title, + hours: _selectedHour, + minutes: _selectedMinute, + seconds: _selectedSecond); Navigator.of(context).pop(task); } @@ -86,7 +92,7 @@ class _NewTaskPageState extends State { return null; }, decoration: InputDecoration( - hintText: 'Task Title', + hintText: 'Task Title', counterText: _maxTitleLength.toString(), filled: true, hasFloatingPlaceholder: false, @@ -99,10 +105,23 @@ class _NewTaskPageState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ - Text('Duration', - maxLines: 1, style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold), + Text( + 'Duration', + maxLines: 1, + style: TextStyle( + fontSize: 22, fontWeight: FontWeight.bold), ), - SizedBox(height: 12), + _durationError == '' + ? SizedBox.shrink() + : SizedBox( + height: 12, + child: Text( + _durationError, + maxLines: 1, + style: + TextStyle(fontSize: 12, color: Colors.red), + ), + ), Row( children: [ Expanded( @@ -218,7 +237,7 @@ class _SelectorState extends State<_Selector> { widget.itemBuilder(item), style: TextStyle( fontSize: 14, - color: isSelected ? Theme.of(context).accentColor : Colors.grey, + color: isSelected ? Theme.of(context).accentColor : Colors.grey, fontWeight: isSelected ? FontWeight.bold : FontWeight.normal), ), ); @@ -226,9 +245,8 @@ class _SelectorState extends State<_Selector> { onSelectedItemChanged: (i) { setState(() { _currentIndex = i; - widget.onSelectedItemChanged( widget.items.elementAt(i)); + widget.onSelectedItemChanged(widget.items.elementAt(i)); }); - }, ); } From 86cd7499a890c5cfea9d8ab2100ae71b91df0301 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 10 Feb 2020 14:39:52 -0600 Subject: [PATCH 2/2] remove fixed height for error text --- lib/pages/new_task_page.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/pages/new_task_page.dart b/lib/pages/new_task_page.dart index c8c6ab6..a6f28fc 100644 --- a/lib/pages/new_task_page.dart +++ b/lib/pages/new_task_page.dart @@ -114,7 +114,6 @@ class _NewTaskPageState extends State { _durationError == '' ? SizedBox.shrink() : SizedBox( - height: 12, child: Text( _durationError, maxLines: 1,