mirror of
https://github.com/bimsina/notes-app.git
synced 2025-08-06 19:15:58 +08:00
Empty title fix.
This commit is contained in:
@ -24,6 +24,7 @@ class NoteDetailState extends State<NoteDetail> {
|
|||||||
TextEditingController titleController = TextEditingController();
|
TextEditingController titleController = TextEditingController();
|
||||||
TextEditingController descriptionController = TextEditingController();
|
TextEditingController descriptionController = TextEditingController();
|
||||||
int color;
|
int color;
|
||||||
|
bool isEdited = false;
|
||||||
|
|
||||||
NoteDetailState(this.note, this.appBarTitle);
|
NoteDetailState(this.note, this.appBarTitle);
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ class NoteDetailState extends State<NoteDetail> {
|
|||||||
color = note.color;
|
color = note.color;
|
||||||
return WillPopScope(
|
return WillPopScope(
|
||||||
onWillPop: () {
|
onWillPop: () {
|
||||||
showDiscardDialog(context);
|
isEdited ? showDiscardDialog(context) : moveToLastScreen();
|
||||||
},
|
},
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
@ -47,7 +48,7 @@ class NoteDetailState extends State<NoteDetail> {
|
|||||||
leading: IconButton(
|
leading: IconButton(
|
||||||
icon: Icon(Icons.arrow_back_ios, color: Colors.black),
|
icon: Icon(Icons.arrow_back_ios, color: Colors.black),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
showDiscardDialog(context);
|
isEdited ? showDiscardDialog(context) : moveToLastScreen();
|
||||||
}),
|
}),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
IconButton(
|
IconButton(
|
||||||
@ -55,7 +56,11 @@ class NoteDetailState extends State<NoteDetail> {
|
|||||||
Icons.save,
|
Icons.save,
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
),
|
),
|
||||||
onPressed: _save,
|
onPressed: () {
|
||||||
|
titleController.text.length == 0
|
||||||
|
? showEmptyTitleDialog(context)
|
||||||
|
: _save();
|
||||||
|
},
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(Icons.delete, color: Colors.black),
|
icon: Icon(Icons.delete, color: Colors.black),
|
||||||
@ -72,6 +77,7 @@ class NoteDetailState extends State<NoteDetail> {
|
|||||||
PriorityPicker(
|
PriorityPicker(
|
||||||
selectedIndex: 3 - note.priority,
|
selectedIndex: 3 - note.priority,
|
||||||
onTap: (index) {
|
onTap: (index) {
|
||||||
|
isEdited = true;
|
||||||
note.priority = 3 - index;
|
note.priority = 3 - index;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -81,6 +87,7 @@ class NoteDetailState extends State<NoteDetail> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
color = index;
|
color = index;
|
||||||
});
|
});
|
||||||
|
isEdited = true;
|
||||||
note.color = index;
|
note.color = index;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -125,6 +132,8 @@ class NoteDetailState extends State<NoteDetail> {
|
|||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.all(Radius.circular(10.0))),
|
||||||
title: Text(
|
title: Text(
|
||||||
"Discard Changes?",
|
"Discard Changes?",
|
||||||
style: Theme.of(context).textTheme.body1,
|
style: Theme.of(context).textTheme.body1,
|
||||||
@ -159,11 +168,43 @@ class NoteDetailState extends State<NoteDetail> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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: <Widget>[
|
||||||
|
FlatButton(
|
||||||
|
child: Text("Okay",
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.body1
|
||||||
|
.copyWith(color: Colors.purple)),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void showDeleteDialog(BuildContext context) {
|
void showDeleteDialog(BuildContext context) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.all(Radius.circular(10.0))),
|
||||||
title: Text(
|
title: Text(
|
||||||
"Delete Note?",
|
"Delete Note?",
|
||||||
style: Theme.of(context).textTheme.body1,
|
style: Theme.of(context).textTheme.body1,
|
||||||
@ -203,10 +244,12 @@ class NoteDetailState extends State<NoteDetail> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateTitle() {
|
void updateTitle() {
|
||||||
|
isEdited = true;
|
||||||
note.title = titleController.text;
|
note.title = titleController.text;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateDescription() {
|
void updateDescription() {
|
||||||
|
isEdited = true;
|
||||||
note.description = descriptionController.text;
|
note.description = descriptionController.text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,10 @@ class NoteListState extends State<NoteList> {
|
|||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(this.noteList[index].description,
|
child: Text(
|
||||||
|
this.noteList[index].description == null
|
||||||
|
? ''
|
||||||
|
: this.noteList[index].description,
|
||||||
style: Theme.of(context).textTheme.body2),
|
style: Theme.of(context).textTheme.body2),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
Reference in New Issue
Block a user