From 517f49ef4c8fe8e47b87eefcfa524cf1415ef4d0 Mon Sep 17 00:00:00 2001 From: Bibek Timsina Date: Thu, 9 May 2019 16:56:33 +0545 Subject: [PATCH] Empty title fix. --- lib/screens/note_detail.dart | 49 +++++++++++++++++++++++++++++++++--- lib/screens/note_list.dart | 5 +++- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/lib/screens/note_detail.dart b/lib/screens/note_detail.dart index 6dfa5d7..a7e0dec 100644 --- a/lib/screens/note_detail.dart +++ b/lib/screens/note_detail.dart @@ -24,6 +24,7 @@ class NoteDetailState extends State { TextEditingController titleController = TextEditingController(); TextEditingController descriptionController = TextEditingController(); int color; + bool isEdited = false; NoteDetailState(this.note, this.appBarTitle); @@ -34,7 +35,7 @@ class NoteDetailState extends State { color = note.color; return WillPopScope( onWillPop: () { - showDiscardDialog(context); + isEdited ? showDiscardDialog(context) : moveToLastScreen(); }, child: Scaffold( appBar: AppBar( @@ -47,7 +48,7 @@ class NoteDetailState extends State { leading: IconButton( icon: Icon(Icons.arrow_back_ios, color: Colors.black), onPressed: () { - showDiscardDialog(context); + isEdited ? showDiscardDialog(context) : moveToLastScreen(); }), actions: [ IconButton( @@ -55,7 +56,11 @@ class NoteDetailState extends State { Icons.save, color: Colors.black, ), - onPressed: _save, + onPressed: () { + titleController.text.length == 0 + ? showEmptyTitleDialog(context) + : _save(); + }, ), IconButton( icon: Icon(Icons.delete, color: Colors.black), @@ -72,6 +77,7 @@ class NoteDetailState extends State { PriorityPicker( selectedIndex: 3 - note.priority, onTap: (index) { + isEdited = true; note.priority = 3 - index; }, ), @@ -81,6 +87,7 @@ class NoteDetailState extends State { setState(() { color = index; }); + isEdited = true; note.color = index; }, ), @@ -125,6 +132,8 @@ class NoteDetailState extends State { context: context, builder: (BuildContext context) { return AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(10.0))), title: Text( "Discard Changes?", style: Theme.of(context).textTheme.body1, @@ -159,11 +168,43 @@ class NoteDetailState extends State { ); } + void showEmptyTitleDialog(BuildContext context) { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(10.0))), + title: Text( + "Title is empty!", + style: Theme.of(context).textTheme.body1, + ), + content: Text('The title of the note cannot be empty.', + style: Theme.of(context).textTheme.body2), + actions: [ + FlatButton( + child: Text("Okay", + style: Theme.of(context) + .textTheme + .body1 + .copyWith(color: Colors.purple)), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); + } + void showDeleteDialog(BuildContext context) { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(10.0))), title: Text( "Delete Note?", style: Theme.of(context).textTheme.body1, @@ -203,10 +244,12 @@ class NoteDetailState extends State { } void updateTitle() { + isEdited = true; note.title = titleController.text; } void updateDescription() { + isEdited = true; note.description = descriptionController.text; } diff --git a/lib/screens/note_list.dart b/lib/screens/note_list.dart index bc80a89..0b573c7 100644 --- a/lib/screens/note_list.dart +++ b/lib/screens/note_list.dart @@ -123,7 +123,10 @@ class NoteListState extends State { mainAxisAlignment: MainAxisAlignment.start, children: [ Expanded( - child: Text(this.noteList[index].description, + child: Text( + this.noteList[index].description == null + ? '' + : this.noteList[index].description, style: Theme.of(context).textTheme.body2), ) ],