Provider: Provider in multiples routes

Created on 19 May 2019  路  2Comments  路  Source: rrousselGit/provider

Hello if I want to use Provider.of... in multiples routes, the Provider widget must be a parent of material app? Or I can create de Provider widget in any route(no material app widget) and routes pushed by this widget can use Provider.of... ?

Thanks

Most helpful comment

The general rule is, if two widgets wants to access the same provider, the provider must be a common ancestor of both widgets.
This is true for anything, including routes.

So yes, above add your provider above MaterialApp (or its equivalent)

All 2 comments

To workaround this I pass the context of the route where you provide your dependencies to the new route widget arguments, and to get the dependency I pass the parent context.
I'm not sure if this is a good practice though :)
Eager to know the right solution too.

The general rule is, if two widgets wants to access the same provider, the provider must be a common ancestor of both widgets.
This is true for anything, including routes.

So yes, above add your provider above MaterialApp (or its equivalent)

Was this page helpful?
0 / 5 - 0 ratings