I have a problem. I would like to pop the screen (of main context) when alert dialog is closed. So here how it goes:
- User does some staff.
- Alert dialog is open
- It is open for 3 seconds.
- Alert dialog is closed
- We move user to the main screen (EmailPage for me)
Whole method:
Future<void> _sendMessageToSupport() async {
final body = {
'email': emailController.text, //
'topic': topicController.text, //
'message': contentController.text,
};
final jsonString = json.encode(body);
final uri =
Uri.http(AppConstants.BASE_URL, AppConstants.SUPPORT_CONTACT_ENDPOINT);
final headers = {HttpHeaders.contentTypeHeader: 'application/json'};
_setRefreshProgressIndicator(true);
await http.post(uri, headers: headers, body: jsonString);
_setRefreshProgressIndicator(false);
showDialog(
barrierDismissible: false,
context: context,
builder: (context) {
Future.delayed(
Duration(seconds: 3),
() {
Navigator.of(context).pop(true);
/*Navigator.push(context,
new MaterialPageRoute(builder: (context) => EmailPage()));*/ //navigates to EmailPage rather than pop to it
},
);
return AlertDialog(
title: Text(
'blabla',
style: TextStyle(
fontSize: 18,
color: Color(0xff000000),
),
textAlign: TextAlign.center,
),
);
},
);
}
We move to this screen (let's say A screen) from the EmailPage. User does staff and we should automatically back to the EmailPage. I have made it like this:
Future.delayed(
Duration(seconds: 3),
() {
Navigator.of(context).pop(true);
/*Navigator.push(context,
new MaterialPageRoute(builder: (context) => EmailPage()));*/ //navigates to EmailPage rather than pop
},
);
but the problem is we move user to EmailPage by pushing new screen and then when he clicks on the back arrow on the appbar he is moved to screen A again.
Could you tell me how can I do it? I mean, I know that I need to pop from context of build method, but how? When I did something like this (pop on the end of the method):
builder: (context) {
Future.delayed(
Duration(seconds: 3),
() {
Navigator.of(context).pop(true);
/*Navigator.push(context,
new MaterialPageRoute(builder: (context) => EmailPage()));*/ //navigates to EmailPage rather than pop
},
);
return AlertDialog(
title: Text(
'Wysłano zapytanie do supportu. Postaramy się odpowiedzieć jak najszybciej!',
style: TextStyle(
fontSize: 18,
color: Color(0xff000000),
),
textAlign: TextAlign.center,
),
);
},
);
Navigator.of(context).pop(true);
}
then popup was not even shown.