title: Singin request with firebase is not working
body: <p>I'm having a problem trying to do a login validation with firebase. Coincidentally I can create a new firebase account register it and I can enter my application. but when I go back to the home screen, I can't log in with that registered account. What do you think is the mistake I'm making?.</p>
  <p>The console returns this to me.
  <a href="https://i.stack.imgur.com/CLLFA.jpg" rel="nofollow noreferrer">Error image</a></p>
  <p>my screen code</p>
  <pre><code>class AuthScreen extends StatefulWidget {
    const AuthScreen({Key? key}) : super(key: key);
  
    @override
    State&lt;AuthScreen&gt; createState() =&gt; _AuthScreenState();
  }
  
  class _AuthScreenState extends State&lt;AuthScreen&gt; {
    final _auth = FirebaseAuth.instance;
    var _isLoading = false;
  
    void _submitAuthForm(
      String email,
      String userName,
      String password,
      bool isLogin,
      BuildContext ctx,
    ) async {
      UserCredential authResult;
      try {
        setState(() {
          _isLoading = true;
        });
        if (isLogin) {
          authResult = await _auth.signInWithEmailAndPassword(
              email: email, password: password);
        } else {
          authResult = await _auth.createUserWithEmailAndPassword(
              email: email, password: password);
  
          await FirebaseFirestore.instance
              .collection('users')
              .doc(authResult.user!.uid)
              .set({
            'username': userName,
            'email': email,
          });
        }
      } on PlatformException catch (err) {
        var message = 'An error ocurred, Please check your credentials';
  
        if (err.message != null) {
          message = err.message!;
        }
        Scaffold.of(ctx).showSnackBar(SnackBar(
          content: Text(message),
          backgroundColor: Theme.of(ctx).errorColor,
        ));
        setState(() {
          _isLoading = false;
        });
      } catch (err) {
        print(err);
        setState(() {
          _isLoading = false;
        });
      }
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        backgroundColor: Theme.of(context).primaryColor,
        body: AuthForm(_submitAuthForm, _isLoading),
      );
    }
  }
  
  </code></pre>
  <p>authentication code</p>
  <pre><code>class AuthForm extends StatefulWidget {
    AuthForm(this.submitFn, this.isLoading);
  
    final bool isLoading;
    final void Function(String email, String userName, String password,
        bool isLogin, BuildContext ctx) submitFn;
  
    @override
    State&lt;AuthForm&gt; createState() =&gt; _AuthFormState();
  }
  
  class _AuthFormState extends State&lt;AuthForm&gt; {
    final _formKey = GlobalKey&lt;FormState&gt;();
    var _isLogin = true;
    var _userEmail = '';
    var _userName = '';
    var _userPassword = '';
  
    void _trySubmit() {
      final isValid = _formKey.currentState!.validate();
      FocusScope.of(context).unfocus();
  
      if (isValid) {
        _formKey.currentState!.save();
        widget.submitFn(
          _userEmail.trim(),
          _userPassword.trim(),
          _userName.trim(),
          _isLogin,
          context,
        );
      }
    }
  
    @override
    Widget build(BuildContext context) {
      return Center(
          child: Card(
        margin: EdgeInsets.all(20),
        child: SingleChildScrollView(
          child: Padding(
            padding: EdgeInsets.all(16),
            child: Form(
                key: _formKey,
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: &lt;Widget&gt;[
                    TextFormField(
                      key: ValueKey('email'),
                      validator: (value) {
                        if (value!.isEmpty ||
                            !value.contains('@') ||
                            !value.contains('.com')) {
                          return 'Please enter a valid email';
                        }
                        return null;
                      },
                      keyboardType: TextInputType.emailAddress,
                      decoration: InputDecoration(labelText: 'Email address'),
                      onSaved: (value) {
                        _userEmail = value!;
                      },
                    ),
                    if (!_isLogin)
                      TextFormField(
                        key: ValueKey('username'),
                        validator: (value) {
                          if (value!.isEmpty || value.length &lt; 4) {
                            return 'Please enter at least 4 characters';
                          }
                          return null;
                        },
                        decoration: InputDecoration(labelText: 'Username'),
                        onSaved: (value) {
                          _userName = value!;
                        },
                      ),
                    TextFormField(
                      key: ValueKey('password'),
                      validator: (value) {
                        if (value!.isEmpty || value.length &lt; 7) {
                          return 'Password must be at least 7 characters long';
                        }
                        return null;
                      },
                      decoration: InputDecoration(labelText: 'Password'),
                      obscureText: true,
                      onSaved: (value) {
                        _userPassword = value!;
                      },
                    ),
                    SizedBox(
                      height: 15,
                    ),
                    if (widget.isLoading) CircularProgressIndicator(),
                    if (!widget.isLoading)
                      ElevatedButton(
                        onPressed: _trySubmit,
                        child: Text(_isLogin ? 'Login' : 'Signup'),
                      ),
                    if (!widget.isLoading)
                      TextButton(
                          onPressed: () {
                            setState(() {
                              _isLogin = !_isLogin;
                            });
                          },
                          child: Text(_isLogin
                              ? 'Create new account'
                              : 'I already have a account'))
                  ],
                )),
          ),
        ),
      ));
    }
  }
  
  
  </code></pre>