There are 3 ways the AlertDialog can be dismissed (in my example):
- Tapping outside its barrier. ('to cancel')
- Tapping a button A which will call pop(). ('to proceed')
- Tapping a button B which will call pop(). (to 'cancel')
I wish to run some code in a then() callback after the AlertDialog is closed. This code will be dependent on HOW it was closed.
Note: I am using the then() callback so I can detect if the AlertDialog was dismissed not by a button.
Is this possible?
showDialog(context: context, builder: (context) => AlertDialog(
title: Text('Grant access'),
actions: [
/// Button 'A'
OutlinedButton(onPressed: (){
Navigator.of(context).pop();
/// Some more code
}, child: Text('Grant access')),
/// Button 'B'
OutlinedButton(onPressed: () {
Navigator.of(context).pop();
}, child: Text('Cancel'))
],
)).then((value) async {
// Code after closure. Can I detect what way the AlertDialog was dismissed?
});