Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh a page after back button pressed

Tags:

flutter

dart

I have a "list page". and an add page. User clicks "add page", goes to a new page where they add some entity. Then I pop the Navigator, and user goes back to "list page".

At this point, I want to get notified somehow - callback maybe? override a method, I am not really sure - and re-read the information from database.

Is there a hook like this in Flutter? Or is there another pattern that I should use?

like image 238
Arash Avatar asked Apr 20 '18 03:04

Arash


People also ask

How do I trigger a refresh page?

You can use the location. reload() JavaScript method to reload the current URL. This method functions similarly to the browser's Refresh button. The reload() method is the main method responsible for page reloading.

What happens when browser Back button is pressed?

In javascript, navigation type 2 means browser's back or forward button clicked and the browser is actually taking content from cache. This doesn't work on a single page application, the result is always 1 (which means reload).

How do I force a HTML page to refresh?

In most web browsers you can force a one-time page load from the server by holding down the shift key while clicking on the Reload or Refresh button.


1 Answers

The Navigator.push method returns a future of the generic type of the Route:

Navigator.of(context)   .push(new MaterialPageRoute<String>(...))   .then((String value) {     print(value);   }); 

And inside the new route, when you have the value you need:

Navigator.of(context).pop('String'); 
like image 150
Ian Avatar answered Sep 17 '22 22:09

Ian