How to keep login active Flutter Firebase

Asked

Viewed 30 times

0

Good afternoon, I’m having a hard time keeping my login active in my app, either by email or by google account. I tried the Sharedpreferences method but I was not very successful.

This is the login button code:

DefaultButton(
        text: "Continuar",
        press: () async {
          if (_formKey.currentState.validate()) {
            _formKey.currentState.save();
            try {
              KeyboardUtil.hideKeyboard(context);
              UserCredential user = await FirebaseAuth.instance
                  .signInWithEmailAndPassword(
                  email: email,
                  password: password);               
              Navigator.of(context).pushAndRemoveUntil( 
                  MaterialPageRoute(builder: (context) => Tabs()),  
                      (Route<dynamic> route) => false);
            } on FirebaseAuthException catch (e) {
              if (e.code == 'user-not-found') { 
                Fluttertoast.showToast(
                    msg: "Nenhum usuário encontrado para esse e-mail.");
                print('Nenhum usuário encontrado para esse e-mail.');
              } else if (e.code == 'wrong-password') {
                Fluttertoast.showToast( 
                    msg: "Senha errada fornecida para esse usuário.");
                print('Senha errada fornecida para esse usuário.');
              }
            }
          }
        },
      ),

Thank you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.