Reputation: 2051
In my app, the first screen navigates to the second screen through Navigator.of(context).push
. Then the second screen navigates to the third screen through Navigator.pushReplacement
. When I pop
on the third screen, the app will back to the first screen, skipping the second screen.
If I want to pass data back from the second screen to the first screen, I can simply use await Navigator.push(context)
on my first screen, then when I pop
on the second screen, I can pass in the data in context. However, in this case, which involves 3 screens, I can't use that.
Upvotes: 0
Views: 1422
Reputation: 1562
I've pushed a flutter project solving your issue using the bloc pattern for state management. The app has 3 pages. The first and second have only simple labels wrapped in tap gesture(navigation). On the third is the input that changes the value of the labels on page one and two. git repo
This the official documentation regarding flutter state management flutter state management
Upvotes: 1
Reputation: 71
Use Navigator.of(context).push to go second screen to Third screen, and when you pop the third screen your code which is present in .then in seond screen will pop the second screen and pass the data of second screen to first screen.
first screen to second:-
Navigator.push(context, CupertinoPageRoute(
builder: (context)=>SecondScreen()
)).then((value){ //value is the data which you pass while poping the second screen
});
second screen to third:-
Navigator.push(context, CupertinoPageRoute(
builder: (context)=>ThirdScreen()
)).then((value){
Navigator.pop(context,your data)
});
Upvotes: 1
Reputation: 942
I'd suggest you read the docs about state management in Flutter.
I've found the Provider
pattern especially helpful for this.
Upvotes: 0