Assume this scenario: page1 Navigator.push to page2. user on page2 clicks the back button, so page2 pops and page1 regains view. How do I catch this event on page1?
You can check like this by passing parameter from Navigator.pop...
from the second screen:-
Navigator.pop(context, 'updateList'),
and on the first screen check like this and pass condition which you want:-
FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
new ManageAssignments(),
),
).then((val) {
if (val == 'updateList') getAssignementList();
});
},
backgroundColor: Theme.of(context).primaryColor,
child: Icon(Icons.add),
)
Hope it will work for you :-)
So when Navigator.push() happens it returns a Future. And on Navigator.pop() the future is resolved. You can return value from Navigator.pop like this Navigator.pop(context, "MyResult"); That result will be captured like this - final result = Navigator.push(). You can use the result in the widget from where Navigator.push() was called.
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