'How can get a pop page result in navigator2
I am ready to use Navigator2 instead of Navigator1 in my flutter app. There are two pages, Page1 and Page2. Page1 can push to Page2. When pop Page2 I want to pass a result to Page1. In Navigator1 I can make it likes below:
Page1:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Page2()
)
).then((result){
//do something
});
Page2:
Navigator.pop(context, result);
How can I do it using Navigator2.
Solution 1:[1]
Save the Navigator.push future in popResult variable. The popResult value will be which you have passed from Navigator.pop(context, popResult) of Page 2;
final popResult = await Navigator.push(
context,
MaterialPageRoute(builder: (context) => const Page2()),
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | shraddha11 |