Closed rxxxxxxb closed 5 years ago
The easiest way would be to wrap your HomePage
with a Provider<User>
, and return this in the LandingPage
:
Provider<User>.value(
value: user,
child: HomePage(),
)
Then, in the HomePage
or any descendent widgets, you can access it with Provider.of<User>(context)
.
Thansks for this great example of providers, I'm trying to get my head around this. It works fine for HomePage to get access to the user like that, but when I push a named route and try to access the user data I get Ensure the Provider
@urbanmania this happens because when you use Navigator.push
, the new route is added as a child of the MaterialApp
, and this is not a child of the LandingPage
.
See the EmailPasswordSignInPage
in this diagram for an example of this:
https://github.com/bizz84/firebase_auth_demo_flutter/blob/master/media/simplified-widget-tree.png
One solution is to call Provider.of<User>(context)
before pushing the new route, and injecting the User
as a constructor argument to the new widget.
@urbanmania see #39 which moves the auth StreamBuilder
above the MaterialApp
. This should fix any problems with Providers not found.
Thank you for sharing this amazing repo.
Just a quick request/question.