Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The argument type 'StreamSubscription<User?>' can't be assigned to the parameter type 'Stream<String>?'

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();
      },
    );
  }
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading