From 2fd62ebfa1c12eaf18c3b30c29089893ce4ccaa0 Mon Sep 17 00:00:00 2001 From: Giorgio Bertolotti Date: Thu, 17 Oct 2019 00:06:25 +0200 Subject: [PATCH] :bug: Bug fix on project creation, fixed #7, added check on empty project name --- pro_time/lib/model/project.dart | 10 ++-- .../lib/resources/new_project_dialog.dart | 59 ++++++++++++------- pro_time/lib/ui/home.dart | 3 +- 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/pro_time/lib/model/project.dart b/pro_time/lib/model/project.dart index ebf764e..854e61d 100644 --- a/pro_time/lib/model/project.dart +++ b/pro_time/lib/model/project.dart @@ -5,10 +5,12 @@ class Project { this.name, this.mainColor, this.textColor, - DateTime created = DateTime.now(), - List activities = List(), - bool notificationEnabled = true, - }) : this.created = created ?? DateTime.now(), this.activities = activities ?? List(), this.notificationEnabled ? notificationEnabled ?? true; + DateTime created, + List activities, + bool notificationEnabled, + }) : this.created = created ?? DateTime.now(), + this.activities = activities ?? List(), + this.notificationEnabled = notificationEnabled ?? true; String get id => (created.millisecondsSinceEpoch).toString(); String name; diff --git a/pro_time/lib/resources/new_project_dialog.dart b/pro_time/lib/resources/new_project_dialog.dart index f88c108..2ad1777 100644 --- a/pro_time/lib/resources/new_project_dialog.dart +++ b/pro_time/lib/resources/new_project_dialog.dart @@ -21,6 +21,7 @@ class _NewProjectDialogState extends State { Color _tmpMainColor; Color _tmpTextColor; bool _editMode; + bool _nameValid = false; @override void initState() { @@ -36,6 +37,8 @@ class _NewProjectDialogState extends State { _selectedTextColor = widget.projectToEdit.textColor; _tmpMainColor = widget.projectToEdit.mainColor; _tmpTextColor = widget.projectToEdit.textColor; + if (widget.projectToEdit.name != null && + widget.projectToEdit.name.isNotEmpty) _nameValid = true; } super.initState(); } @@ -54,6 +57,18 @@ class _NewProjectDialogState extends State { hintText: "Enter project name", border: UnderlineInputBorder(), ), + onChanged: (value) { + if (!_nameValid && (value != null && value.isNotEmpty)) { + setState(() { + _nameValid = true; + }); + } + if (_nameValid && (value == null || value.isEmpty)) { + setState(() { + _nameValid = false; + }); + } + }, ), SizedBox(height: 10.0), Row( @@ -118,25 +133,27 @@ class _NewProjectDialogState extends State { FlatButton( textColor: Colors.lightBlue, child: Text(_editMode ? "Update" : "Add"), - onPressed: () { - Project proj; - if (_editMode) { - proj = widget.projectToEdit; - proj.name = _nameController.text; - proj.mainColor = _selectedMainColor; - proj.textColor = _selectedTextColor; - } else { - proj = Project( - name: _nameController.text, - mainColor: _selectedMainColor, - textColor: _selectedTextColor, - created: DateTime.now(), - activities: List(), - ); - } - Hive.box("projects").put(proj.id, proj); - Navigator.of(context).pop(); - }, + onPressed: !_nameValid + ? null + : () { + Project proj; + if (_editMode) { + proj = widget.projectToEdit; + proj.name = _nameController.text; + proj.mainColor = _selectedMainColor; + proj.textColor = _selectedTextColor; + } else { + proj = Project( + name: _nameController.text, + mainColor: _selectedMainColor, + textColor: _selectedTextColor, + created: DateTime.now(), + activities: List(), + ); + } + Hive.box("projects").put(proj.id, proj); + Navigator.of(context).pop(); + }, ), ], ); @@ -198,8 +215,8 @@ class _NewProjectDialogState extends State { child: Text("Select"), onPressed: () { setState(() { - _selectedMainColor = _tmpMainColor; - _selectedTextColor = _tmpTextColor; + if (_tmpMainColor != null) _selectedMainColor = _tmpMainColor; + if (_tmpTextColor != null) _selectedTextColor = _tmpTextColor; }); Navigator.of(context).pop(); }, diff --git a/pro_time/lib/ui/home.dart b/pro_time/lib/ui/home.dart index 66b3c73..56285e6 100644 --- a/pro_time/lib/ui/home.dart +++ b/pro_time/lib/ui/home.dart @@ -208,7 +208,7 @@ class _HomePageState extends State { backgroundColor: Colors.white, child: Icon( Icons.add, - size: 38.0, + size: 44.0, color: Colors.black, ), ), @@ -261,6 +261,7 @@ class _HomePageState extends State { style: TextStyle( color: appState.getCurrentProject().textColor, fontSize: 22.0, + fontWeight: FontWeight.w700, ), maxLines: 1, overflow: TextOverflow.ellipsis,