Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect when we moved back to previous page in Flutter

Tags:

flutter

dart

We moved from Page1 to Page2 but now from Page2 we move back again to Page1 like this:

Navigator.of(context).pop();

How can we detect on Page1 that we went back?

like image 697
Dani Avatar asked Dec 20 '19 10:12

Dani


People also ask

How do I use pull to refresh in Flutter?

Pull to refresh (swipe to refresh) feature can be implemented in flutter using RefreshIndicator widget. Pull (swipe) to refresh feature lets the user refresh current data or fetch updated data from the server by pulling down on a list.

How to return to the first route in flutter?

Return to the first route using Navigator.pop () Most apps contain several screens for displaying different types of information. For example, an app might have a screen that displays products. When the user taps the image of a product, a new screen displays details about the product. Terminology: In Flutter, screens and pages are called routes .

What are screens and pages in flutter?

Most apps contain several screens for displaying different types of information. For example, an app might have a screen that displays products. When the user taps the image of a product, a new screen displays details about the product. Terminology: In Flutter, screens and pages are called routes .

How do I refresh a page in materialpageroute?

Navigator.push ( context, MaterialPageRoute ( builder: (context) => SecondPage ()), ).then ( (value) => setState ( () {})); After you pop back from SecondPage () to FirstPage () the "then" statement will run and refresh the page.

How to refresh the page after i pop back from secondpage ()?

After you pop back from SecondPage () to FirstPage () the "then" statement will run and refresh the page. Sorry, something went wrong. This can be done with the help of RouteAware


2 Answers

Navigator.push(
    context,
    MaterialPageRoute(
      builder: (context) => NextPage(),
    ),
  ).then((_){
// Here you will get callback after coming back from NextPage()
// Do your code here
});
like image 155
Jay Mungara Avatar answered Nov 12 '22 01:11

Jay Mungara


In your Page1, When you push Page2 wait for it to pop

Future<void> _goToPage2() async {
  await Navigator.push(
    context,
    MaterialPageRoute(
      builder: (context) => Page2(),
    ),
  );
  print("Page2 is popped");
}
like image 35
Crazy Lazy Cat Avatar answered Nov 12 '22 03:11

Crazy Lazy Cat