title: An exception was throw by _MapStream<FirebaseUser, User> listened by StreamProvider<User>, but no `catchError` was provided
body: <p>&lt;--- UPDATE ---&gt;</p>
  <p>FOUND THE SOLUTION. CHECK ANSWER BELOW</p>
  <p>&lt;--- UPDATE ---&gt;</p>
  <p>Any ideas why this is happening, what causes the bug, and how do I fix it?</p>
  <p>I was following TheNetNinja's tutorial on YouTube and I've seen people had a similar problem, but not quite the same.</p>
  <p>An exception is thrown when the app is closed suddenly (using the stop button in Android Studio) without logging out and then restarted, only when using e-mail and pass login. For Google login, it seems to work fine. Also, this doesn't happen if I manually create a new user in Firebase Console and login for the first time.</p>
  <p>THE EXCEPTION:</p>
  <pre><code>════════ Exception caught by provider ══════════════════════════════════════════════════════════════
  The following assertion was thrown:
  An exception was throw by _MapStream&lt;FirebaseUser, User&gt; listened by
  
  StreamProvider&lt;User&gt;, but no `catchError` was provided.
  
  Exception:
  RangeError (index): Invalid value: Only valid value is 0: 1
  
  ════════════════════════════════════════════════════════════════════════════════════════════════════
  </code></pre>
  <p>I'm using <code>firebase_auth: ^0.16.0</code> in my pubspec.yaml and I'm thinking it might have something to do with the version.</p>
  <p>When I log in, I get this output</p>
  <pre><code>I/BiChannelGoogleApi(17821): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq@cd1fa83
  D/FirebaseAuth(17821): Notifying id token listeners about user ( 1EMwk8483hQWnSQwJeQYm9AcpiD2 ).
  </code></pre>
  <p>which looks like the account gets verified and logged in, but then the screens don't change, so I guess it gets stuck somewhere in the verification process.</p>
  <p>And the weird thing is, if I log in normally with the exception and restart the app, it works just fine. If I keep restarting it, it works just fine, but if I suddenly stop it, I get the exception again.</p>
  <p>This is my authentication code</p>
  <pre><code>import 'package:firebase_auth/firebase_auth.dart';
  import 'package:flutter/material.dart';
  import 'package:flutter/services.dart';
  import 'package:google_sign_in/google_sign_in.dart';
  import 'package:common_ui_module/Utils.dart';
  import 'package:user_module/Role.dart';
  import 'package:user_module/User.dart';
  import 'package:localization_module/AppLocalizations.dart';
  
  class AuthService {
    final FirebaseAuth _auth = FirebaseAuth.instance;
  
      return user != null
          ? User(uid: user.uid)
          : null;
    }
  
    Stream&lt;User&gt; get user {
      // map FireBaseUsers to User objects
      return _auth.onAuthStateChanged.map(_userFromFireBaseUser);
    }
  
  
  // sign in with email and pass
    Future&lt;User&gt; signInWithEmailAndPassword(String email, String pass) async {
      try {
        AuthResult result =
            await _auth.signInWithEmailAndPassword(email: email, password: pass);
        FirebaseUser user = result.user;
        assert(await user.getIdToken() != null);
        print(
            &quot;Signed in: ${user.email} , pass: $pass, phone: ${user.phoneNumber}&quot;);
  
        /// return the mapped user
        return _userFromFireBaseUser(user);
      } catch (e) {
        print(e.toString());
        return null;
      }
    }
  
  
  // sign out
    Future signOut() async {
      try {
        return await _auth.signOut();
      } catch (e) {
        print(e.toString());
        return null;
      }
    }
  }
  
  </code></pre>
  <p>This is the Wrapper that switches between Login and main screen</p>
  <pre><code>class Wrapper extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      final User user = Provider.of&lt;User&gt;(context);
  
      if (user != null) {
        return RestaurantOrdersScreen();
      } else {
        return LoginScreen();
      }
    }
  }
  </code></pre>
  <p>And I've wrapped the main application in a MultiProvider:</p>
  <pre><code>Widget build(BuildContext context) {
      return MultiProvider(
        providers: [
          /// PROVIDER FOR AUTHENTICATION
          StreamProvider&lt;User&gt;.value(
            value: AuthService().user,
          ),
  
         //...
         // some other providers
        ],
        child: MaterialApp(
          home: SplashScreen(),
        ),
      );
    }
  </code></pre>