mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
NoteViewer: Show a confirmation dialog before deleting
This commit is contained in:
@ -48,17 +48,7 @@ class NoteBrowsingScreenState extends State<NoteBrowsingScreen> {
|
||||
IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
onPressed: () {
|
||||
final stateContainer = StateContainer.of(context);
|
||||
var noteIndex = _currentIndex();
|
||||
Note note = widget.notes[noteIndex];
|
||||
stateContainer.removeNote(note);
|
||||
Navigator.pop(context);
|
||||
|
||||
print("Shwoing an undo snackbar");
|
||||
var snackbar = buildUndoDeleteSnackbar(context, note, noteIndex);
|
||||
_scaffoldKey.currentState
|
||||
..removeCurrentSnackBar()
|
||||
..showSnackBar(snackbar);
|
||||
showDialog(context: context, builder: _buildAlertDialog);
|
||||
},
|
||||
),
|
||||
],
|
||||
@ -83,6 +73,41 @@ class NoteBrowsingScreenState extends State<NoteBrowsingScreen> {
|
||||
assert(currentIndex < widget.notes.length);
|
||||
return currentIndex;
|
||||
}
|
||||
|
||||
void _deleteNote(BuildContext context) {
|
||||
final stateContainer = StateContainer.of(context);
|
||||
var noteIndex = _currentIndex();
|
||||
Note note = widget.notes[noteIndex];
|
||||
stateContainer.removeNote(note);
|
||||
Navigator.pop(context);
|
||||
|
||||
print("Shwoing an undo snackbar");
|
||||
var snackbar = buildUndoDeleteSnackbar(context, note, noteIndex);
|
||||
_scaffoldKey.currentState
|
||||
..removeCurrentSnackBar()
|
||||
..showSnackBar(snackbar);
|
||||
}
|
||||
|
||||
Widget _buildAlertDialog(BuildContext context) {
|
||||
var title = "Are you sure you want to delete this Journal Entry?";
|
||||
|
||||
return AlertDialog(
|
||||
content: Text(title),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text('Keep It'),
|
||||
),
|
||||
FlatButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context); // Alert box
|
||||
_deleteNote(context);
|
||||
},
|
||||
child: Text('Delete It'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class NoteViewer extends StatelessWidget {
|
||||
|
Reference in New Issue
Block a user