I've three different MaterialPage
. So I use Navigator.push
to go from 1 -> 2 -> 3.
Now, page 1 make an HTTP request to GET
a model that is then used in page 1, 2 and 3.
At the end of the process an action on page 3 triggers some modification of the model on the server. How can I update the tree pages on the stack to reflect these changes? In order to do that I need to make a GET
request again.
Should I pass a callback from page 1 to 3 and then go back all the way up to page 1 (and then down again...), or duplicate the HTTP request in page 3? Or something else?
I've attached a schema, in order to clarify (I hope) my explanation. Thanks in advance.
Asked
Active
Viewed 280 times
2

Jumpa
- 4,319
- 11
- 52
- 100
-
what state management system you are using? – reza Feb 05 '22 at 09:32
-
You could just use a global `state` for that, so all your components update automatically as soon as the `Model` state/variable changes. Upon that, you can rebuild your widget or whatsoever. – Thunermay Feb 05 '22 at 09:40
-
Use a state management like Riverpod; GetIt etc... Or use the await Navigator.push like https://www.youtube.com/watch?v=d-JyTMKWzsI – mario francois Feb 05 '22 at 10:49
-
I'm not using a state management tool at the moment, I've had a look at provider, but what confuse me is that I've different Pages not a single tree with children. Where should i put the GET Logic? Where should i define the model? At root level? – Jumpa Feb 05 '22 at 11:36
-
I'd suggest using flutter_bloc and look at cubits. Working in Flutter without a proper state management is very difficult. You can perform the networking in the cubit (in case you don't have a proper structure with repository pattern for example) and emit states to widgets listening to this cubit. – Abed Elaziz Shehadeh Feb 05 '22 at 15:15
-
does your UPDATE request return the updated model from server or you must perform a GET again to get the updated model ? – Calvin Gonsalves Feb 05 '22 at 16:35
-
@CalvinGonsalves I must perform a GET again. – Jumpa Feb 05 '22 at 19:29