Flutter - Run function after showDialog is dismissed
showDialog() can await a callback, and Navigator.pop can pass a value back. so instead of:
Future<Null> gewinner(int gewinner_team, List<String> spieler){
return showDialog(
....
);
}
you can use:
Future<Null> gewinner(int gewinner_team, List<String> spieler) async {
String returnVal = await showDialog(
....
);
}
and then in the dialog builder/screen you simply pop with a return value:
Navigator.pop(context, 'success');
and then do with the returnVal
what you wish.
if (returnVal == 'success') {
...
}
if the dialog is dismissed then returnVal
will be null.
Here is the simple example of getting status from Alert Dialog
RaisedButton(
onPressed: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Are you sure?'),
content: Text('Do you want to remove item?'),
actions: <Widget>[
FlatButton(
onPressed: () => Navigator.of(context).pop('Success'),
child: Text('NO')),
FlatButton(
onPressed: () => Navigator.of(context).pop('Failure'),
child: Text('YES'))
],
)).then((value) =>
print('Result: ' + value.toString()));
},
child: Text('Show Alert Dialog'),
),