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.
Matteo Preda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3
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
method
you can do something like this:
IMPORTANT Do NOT forget to add
async
in your function.
void _setScreen(String identifiers,int id) async{}
Use Below Code:
await Navigator.of(context).push(MaterialPageRoute(builder: (ctx) => const Page2()));
setState((){});
Now call setState((){});
and any other action you b
need to apply
For instance:
onTap: () async {
await Navigator.of(context).push(MaterialPageRoute(
builder: (ctx) => const Page2()));
//////Call SetState or any other action...
print("do Actions"); }
Let me know if your problem is solved or not.
Happy Coding 🙂