Navigator.pushreturns Futurewhich will be completed when called Navigator.pop(and this can be used to transfer data back to the widget called push). For example, suppose your login button has this handler onPressed:
onPressed: () async {
bool isLoggedIn = await Navigator.pushNamed(context, '/login');
if (isLoggedIn) {
}
}
When your login page invokes Navigator.pop(true), the value Futurewill be completed with the value truethat will be assigned to the variable isLoggedIn. (You will receive nullif the user uses the back button to return to the previous screen.)
This is how it works showDialog.
source
share