I am currently creating a todo app where if I long pressed a task tile, it will pop up a show dialog. After redirecting to the edit page, you can edit and save the changes. However, once you are done, you will be redirected to the homepage but will be welcomed with the previous dialog How do I dismiss the dialog after you have been directed to the edit page?
Here is the code of the show dialog:
Future _showAlert(data) async{
return showDialog<Null>(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return new AlertDialog(
title: new Text('Would you like to make changes?', style: new TextStyle(fontSize: 17.0)),
actions: <Widget>[
new FlatButton(
child: new Text('Edit'),
onPressed: (){
Navigator.push(context, new MaterialPageRoute(builder: (context) => new EditTodoPage(todo: data, todoID: selectedTodoId,)));
},
),
new FlatButton(
child: new Text('Delete'),
onPressed: (){
_delete(selectedTodoId);
Navigator.of(context).pop();
},
)
],
);
}
);
}
Navigator.push
returns a Future that completes after calling Navigator.pop
on your edit page.
You can dismiss your dialog after that, like this:
onPressed: () {
Navigator.push(/* ... */)
.then((result) {
Navigator.of(context).pop();
});
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With