Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
🐛 Bug fix on project creation, fixed #7, added check on empty project…
Browse files Browse the repository at this point in the history
… name
  • Loading branch information
GiorgioBertolotti committed Oct 16, 2019
1 parent 2edfcc8 commit 2fd62eb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 26 deletions.
10 changes: 6 additions & 4 deletions pro_time/lib/model/project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ class Project {
this.name,
this.mainColor,
this.textColor,
DateTime created = DateTime.now(),
List<Activity> activities = List(),
bool notificationEnabled = true,
}) : this.created = created ?? DateTime.now(), this.activities = activities ?? List(), this.notificationEnabled ? notificationEnabled ?? true;
DateTime created,
List<Activity> activities,
bool notificationEnabled,
}) : this.created = created ?? DateTime.now(),
this.activities = activities ?? List(),
this.notificationEnabled = notificationEnabled ?? true;

String get id => (created.millisecondsSinceEpoch).toString();
String name;
Expand Down
59 changes: 38 additions & 21 deletions pro_time/lib/resources/new_project_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class _NewProjectDialogState extends State<NewProjectDialog> {
Color _tmpMainColor;
Color _tmpTextColor;
bool _editMode;
bool _nameValid = false;

@override
void initState() {
Expand All @@ -36,6 +37,8 @@ class _NewProjectDialogState extends State<NewProjectDialog> {
_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();
}
Expand All @@ -54,6 +57,18 @@ class _NewProjectDialogState extends State<NewProjectDialog> {
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(
Expand Down Expand Up @@ -118,25 +133,27 @@ class _NewProjectDialogState extends State<NewProjectDialog> {
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<Activity>(),
);
}
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<Activity>(),
);
}
Hive.box("projects").put(proj.id, proj);
Navigator.of(context).pop();
},
),
],
);
Expand Down Expand Up @@ -198,8 +215,8 @@ class _NewProjectDialogState extends State<NewProjectDialog> {
child: Text("Select"),
onPressed: () {
setState(() {
_selectedMainColor = _tmpMainColor;
_selectedTextColor = _tmpTextColor;
if (_tmpMainColor != null) _selectedMainColor = _tmpMainColor;
if (_tmpTextColor != null) _selectedTextColor = _tmpTextColor;
});
Navigator.of(context).pop();
},
Expand Down
3 changes: 2 additions & 1 deletion pro_time/lib/ui/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class _HomePageState extends State<HomePage> {
backgroundColor: Colors.white,
child: Icon(
Icons.add,
size: 38.0,
size: 44.0,
color: Colors.black,
),
),
Expand Down Expand Up @@ -261,6 +261,7 @@ class _HomePageState extends State<HomePage> {
style: TextStyle(
color: appState.getCurrentProject().textColor,
fontSize: 22.0,
fontWeight: FontWeight.w700,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
Expand Down

0 comments on commit 2fd62eb

Please sign in to comment.