如何正确注销用户?

时间:2021-03-08 21:25:31

标签: firebase flutter firebase-authentication

当用户按下退出按钮时,他退出并再次看到登录页面。但问题是他可以再次登录但无法导航到注册页面。我应该说的是,我不使用Stream,也不会使用它。 通常用户可以在登录和注册页面之间切换,我可以使用 toogleview 执行此操作。

这是我按下的注销按钮:

 onPressed:()async{

                          FirebaseAuth.instance.signOut().then((value) => Navigator.pushNamedAndRemoveUntil(context, LoginScreen.route, (route) => true));

                          },

这就是错误:

The following NoSuchMethodError was thrown while handling a gesture:
The method 'call' was called on null.
Receiver: null
Tried calling: call()

When the exception was thrown, this was the stack: 
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
#1      _LoginScreenState._buildSignupBtn.<anonymous closure> (package:projectandroidstudiodenya/authenticate/signin.dart:186:26)
#2      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
#3      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:607:11)
#4      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:296:5)
...
Handler: "onTap"
Recognizer: TapGestureRecognizer#0f596
  debugOwner: GestureDetector
  state: ready
  won arena
  finalPosition: Offset(290.3, 560.3)
  finalLocalPosition: Offset(211.6, 4.3)
  button: 1
  sent tap down

我认为这里有例外:

Widget _buildSignupBtn() {
    return GestureDetector(
      onTap: () {
        widget.toogleView();
      },
      //onTap: () => print('Sign Up Button Pressed'),
      child: RichText(
        text: TextSpan(
          children: [
            TextSpan(
              text: 'Don\'t have an Account? ',
              style: TextStyle(
                color: Colors.white,
                fontSize: 18.0,
                fontWeight: FontWeight.w400,
              ),
            ),
            TextSpan(
              text: 'Sign Up',
              style: TextStyle(
                color: Colors.white,
                fontSize: 18.0,
                fontWeight: FontWeight.bold,
              ),
            ),
          ],
        ),
      ),
    );
  }
 Future<String> signIN(String email, String password) async {
    try {

  (await _auth.signInWithEmailAndPassword(
    email: email.trim(), password: password,)).user?.emailVerified;

        } on FirebaseAuthException catch (e) {

1 个答案:

答案 0 :(得分:1)

试试这个:

 await FirebaseAuth.instance.signOut();
 Navigator.pushNamedAndRemoveUntil(context, LoginScreen.route, (route) => true));

但请确保用户正确登录