Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 32 additions & 15 deletions lib/pages/new_task_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,32 @@ class _NewTaskPageState extends State<NewTaskPage> {
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);
}
Expand Down Expand Up @@ -86,7 +92,7 @@ class _NewTaskPageState extends State<NewTaskPage> {
return null;
},
decoration: InputDecoration(
hintText: 'Task Title',
hintText: 'Task Title',
counterText: _maxTitleLength.toString(),
filled: true,
hasFloatingPlaceholder: false,
Expand All @@ -99,10 +105,22 @@ class _NewTaskPageState extends State<NewTaskPage> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
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(
child: Text(
_durationError,
maxLines: 1,
style:
TextStyle(fontSize: 12, color: Colors.red),
),
),
Row(
children: <Widget>[
Expanded(
Expand Down Expand Up @@ -218,17 +236,16 @@ class _SelectorState<T> 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),
),
);
},
onSelectedItemChanged: (i) {
setState(() {
_currentIndex = i;
widget.onSelectedItemChanged( widget.items.elementAt(i));
widget.onSelectedItemChanged(widget.items.elementAt(i));
});

},
);
}
Expand Down