Reputation: 1553
I want to make multiple routes share the same provider but the only way that I figured out is to wrap those routes inside a nested navigator and the provider is at the top of the nested navigator
any other ways to do such thing
Upvotes: 5
Views: 2319
Reputation: 3842
It is common practice to put the Provider
at the very top of the widget tree. For instance, in the provider example, it sits inside the runApp()
call.
Upvotes: 3
Reputation: 3371
You can pass what is being shared to the new route and to a new Provider widget which can provide it to that route's widget tree. So, you could have a single instance of a bloc class for example accessible to multiple routes, but still only instantiate that bloc once.
Upvotes: -1