zero.one
zero.one

Reputation: 1553

Flutter : Is there anyway to share a provider among multiple routes other than wrapping a nested navigator with the provider?

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

Answers (2)

MickaelHrndz
MickaelHrndz

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

Kris
Kris

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

Related Questions