Here is my _showDialog function:
Future<void> _showDialog({BuildContext context, String msg, String title}) async {
showDialog<bool>(
context: context,
builder: (context) {
return AlertDialog(
title: Text(title),
content: Text(msg),
actions: [
FlatButton(
child: Text('Ok'),
onPressed: () => Navigator.of(context).pop(true),
),
],
);
});
}
Here is my code:
if (result.contains("Error")) {
// Error!!!
// Show ERROR dialog box.
_showDialog(context: context, title: "Error", msg: result);
} else {
// Success!!!
// Show SUCCESS dialog box, then return to the previous screen.
_showDialog(context: context, title: "Success", msg: "Success!");
Navigator.pop(context); // return to the previous screen
}
If error occurs the ERROR dialog box it shows. But if there is no error the SUCCESS dialog box it not show.
If the line
Navigator.pop(context);
is commented out the SUCCESS dialog box it show.
I need to show the SUCCESS dialog box before return to the previous screen.