mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 03:19:11 +08:00
NoteViewer: Show a confirmation dialog before deleting
This commit is contained in:
@ -48,17 +48,7 @@ class NoteBrowsingScreenState extends State<NoteBrowsingScreen> {
|
|||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(Icons.delete),
|
icon: Icon(Icons.delete),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
final stateContainer = StateContainer.of(context);
|
showDialog(context: context, builder: _buildAlertDialog);
|
||||||
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);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -83,6 +73,41 @@ class NoteBrowsingScreenState extends State<NoteBrowsingScreen> {
|
|||||||
assert(currentIndex < widget.notes.length);
|
assert(currentIndex < widget.notes.length);
|
||||||
return currentIndex;
|
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 {
|
class NoteViewer extends StatelessWidget {
|
||||||
|
Reference in New Issue
Block a user