I have bolded where the error line is. I am aware that I have assigned an incorrect type here, but what type should I return based on the error above? Thank you in advance.
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final BaseAuth auth = Provider.of(context).auth;
return StreamBuilder<String>(
stream: **auth.authStateChanges**,
builder: (context, AsyncSnapshot<String> snapshot) {
if (snapshot.connectionState == ConnectionState.active) {
final bool loggedIn = snapshot.hasData;
if (loggedIn == true) {
return HomePage();
} else {
return LoginPage();
}
}
return CircularProgressIndicator();
},
);
}
}
CodePudding user response:
You need to return:
StreamBuilder<User?>(...
Instead of:
StreamBuilder<String>
And change the builder to be of type User, like this:
builder: (context, AsyncSnapshot<User> snapshot) {...
And:
final AuthService auth = Provider.of(context).auth;
Docs: https://pub.dev/documentation/firebase_auth/latest/firebase_auth/FirebaseAuth/authStateChanges.html