Reputation: 3674
class Landing extends StatelessWidget {
const Landing({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
AuthService auth = Provider.of<AuthService>(context);
return StreamBuilder<FirebaseUser>(
stream: auth.onAuthStateChanged,
builder: (contexta, snapshot) {
FirebaseUser user = snapshot.data;
WgService wg = Provider.of<WgService>(context);
if (user == null)
return LoginView();
else
return StreamBuilder<WGDocument>(
stream: wg.streamWG('demowg'),
builder: (contextWG, snapshotWG) {
WGDocument currentWG = snapshotWG.data;
if (currentWG != null)
return SignedInView();
else
return JoinWGScreen();
});
});
}
}
I readed multiple issues with the same error but cant get it fixed by myself. I tried every other context and I do not understand why the error occurs. No IDE errors given.
Upvotes: 0
Views: 30
Reputation: 5086
You need to put a Provider widget on top of your widget. Then you build your widgets as an ancestor of that provider widget. Any descendant can reach the data class of that provider.
Provider<AuthService>(
create: (_) => AuthService(),
child: /* Any widgets below can reach AuthService */
)
Upvotes: 1