I have this code
void _setScreen(String identifiers,int id) {
if (identifiers == _get_Current_Screen_Identifier()) {
Navigator.of(context).pop();
} else {
Navigator.of(context).pop();
if (identifiers == 'page1') {
Navigator.of(context).push(MaterialPageRoute(builder: (ctx) => const Page1()));
}
if (identifiers == 'page2') {
Navigator.of(context).push(MaterialPageRoute(builder: (ctx) => const Page2()));
}
}
}
The first screen to show when I open the application is Page1. In Page2 I can add some kind of value in a table of the DB (sqlite). In Page1, after any kind of operation, I do setState to see if these values are updated/added/delete, but when I returned from Page2 to Page1 the value doesn’t update, until I do some operation that calls setState.
Is there a way to do that?
I’ve tried
void _setScreen(String identifiers,int id) {
if (identifiers == _get_Current_Screen_Identifier()) {
Navigator.of(context).pop();
} else {
Navigator.of(context).pop();
if (identifiers == 'page1') {
Navigator.of(context).push(MaterialPageRoute(builder: (ctx) => const Page1()));
}
if (identifiers == 'page2') {
Navigator.of(context).push(MaterialPageRoute(builder: (ctx) => const Page2())).then(
(value) {
setState(() {
});
});
}
}
}
But it still doesn’t work.
2
Answers
If you go to Page2 and do some actions, then come back to Page1 and want to update your values you can use the
await
methodyou can do something like this:
Use Below Code:
Now call
setState((){});
and any other action you b
need to apply
For instance:
Let me know if your problem is solved or not.
Happy Coding 🙂
Yes, You can
Page 1
In Page 2
Navigator.pop(context,'reloadMe')
instead ofNavigator.pop(context)