Note Deletion: Implement undo

This commit is contained in:
Vishesh Handa
2018-05-25 01:05:17 +02:00
parent 69eb5f2ed5
commit 0551cc0538
2 changed files with 13 additions and 4 deletions

View File

@ -69,7 +69,6 @@ class StateContainerState extends State<StateContainer> {
}
void addNote(Note note) {
print("Adding a note " + note.toString());
setState(() {
note.id = new Uuid().v4();
appState.notes.insert(0, note);
@ -82,6 +81,12 @@ class StateContainerState extends State<StateContainer> {
});
}
void insertNote(int index, Note note) {
setState(() {
appState.notes.insert(index, note);
});
}
// FIXME: Implement this!
void updateNote(Note note) {
setState(() {

View File

@ -38,9 +38,13 @@ class JournalList extends StatelessWidget {
onDismissed: (direction) {
container.removeNote(note);
Scaffold
.of(context)
.showSnackBar(new SnackBar(content: new Text("Note deleted")));
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text("Note deleted"),
action: new SnackBarAction(
label: 'Undo',
onPressed: () => container.insertNote(i, note),
),
));
},
);
},