Answer the question
In order to leave comments, you need to log in
How to handle back to previous page in Flutter?
How to handle back to previous page in Flutter?
That is, I used Navigator.push
, and how to perform certain actions exactly at the moment when the user closes this second page / goes back ?
Answer the question
In order to leave comments, you need to log in
async () {
await Navigator.push() // Предыдущий экран будет ждать результат роута
}
async () {
final int result = await Navigator.push() // Предыдущий экран будет ждать результат роута
// Где-то на другом экране:
navigator.pop(1);
}
Here is how I solved such a problem for a scenario where the user presses the back arrow on the device itself so that a certain page can catch the very moment when the page is retrieved from the history and shown to the user.
I added the "RouteAware" mixin to the class that is the page and overloaded the didPopNext method.
here is an example.
//страница
class CartPage extends StatefulWidget {
@override
_CartPageState createState() {
return _CartPageState();
}
}
//состояние страницы
class _CartPageState extends State<CartPage> with RouteAware {
//вызывается, когда на эту страницу происходит возврат.
@override
void didPopNext() {
_loadCart();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question