When I insert data from other page and pop this page to go back on the listing page, I have to refresh the listing page to get the updated list of data. I want to go back to the updated version of page without pressing refresh button. I am using pushNamed and also I want to have a back arrow button on the input page.
Asked
Active
Viewed 209 times
-1
-
after getting the data from page, do setState to update ui with latest data – Daniyal Dolare May 18 '21 at 11:31
1 Answers
0
Using Navigator.push
or Navigator.pushNamed
returns a Future
object to you.
This Future
resolves when you use Navigator.pop
in the your second screen.
Here is a basic example. Assuming you have function goToNewPage
which you are calling to push a new Screen, you can do it like this.
class Screen1State extends State<Screen1> {
void goToNewPage (context) {
Navigator.of(context).pushNamed('screen2').then((_) {
// The screen2 has popped. so you can just call setState here to just rebuild
// You can do anything you want here, that needs to happen after the new page has been popped.
setState(() {});
});
}
... rest of your code.
Note, the actual implementation of what you should do inside the callback
depends on how your widget is getting data. But you can do anything you want to do after your new page is popped inside that callback
.

Nisanth Reddy
- 5,967
- 1
- 11
- 29