Is there a callback function or a way to know that Navigator.of(context).pop()
's animation back into the previous screen has finished? currently Im using await Future.delayed(Duration(milliseconds: 500));
to accomplish this. Is there a better way?
Im using it for showModalBottomSheet(useRootNavigator: true)
then Navigator.pop()
to close the bottom sheet, then push a new route.
code:
Navigator.of(context).pop();
await Future.delayed(Duration(milliseconds: 500));
Navigator.of(context).push(...) // push new screen
Pushing a route already maintains a Future that completes when a pop occurs. This means you can do this:
Navigator.of(context).pushNamed('/someRoute').then((completion){
//do something
});
The parameter named completion could also be any data you want to retrieve from the screen you are showing. For example let's say I have a group chat and I want to add a user to it. To do that I want to show a screen that allows me to pick a user then pass that user back to the previous screen.
Navigator.of(context).pushNamed('/InviteToChatScreen').then((object) {
if (object != null) {
var user = object as User;
//add them to the chat
}
});
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