Screen 1: shows list of item with add button. Screen 2: form to add a new item to the list.
Screen 2 >> Screen 1 - While calling navigator.pop() in screen 2, how to call method/setState (to update list) in screen 1? Can anyone help me out?
I don't want to relaunch screen again. I just need to run a method to update my list after popping previous screen?
Flutter: Passing Data when Popping Views in Flutter You can replace the code in _MyHomePageState with these: The main magic is in moveToSecondPage where it is an async function, awaiting for the SecondPage to come back with some “data”, which we assign it to information here.
You should make the call of your function in initState rather then in widget tree as everytime the widget is rebuild, it will call the function to execute again and again(leading to more reads).
When you navigate from Screen 1 to Screen 2, you use the push
method. The push
method returns a Future
object.
You can use the then
method of Future
to execute your code after Screen 2 was popped from the navigation stack.
Navigator.of(context)
.push(MaterialPageRoute(
builder: (context) => Screen2(),
))
.then((value) {
// you can do what you need here
// setState etc.
});
You can use Provider or BLoc or you can await for the result when you push the page
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With