使用Firebase身份验证注销时无法再次登录

时间:2020-05-03 17:24:30

标签: firebase flutter dart firebase-authentication

我一直在使用带有Flutter的Firebase实施ID和PW的登录过程。 因此,尽管登录可以正常进行,但是我无法登录然后再登录到登录页面,这让我很生气。 (简而言之,一旦退出,就无法再次登录...) 具体来说,即使您输入身份验证信息并按“登录”按钮,屏幕也不会转到homepage.dart。

错误在下面。

IntersectionObserver

代码在下面。作为调试的结果,标有★的部分使我感到怀疑。 如果您发现任何错误和可疑代码,请教我。 特别感谢!

null
I/flutter (10611): Error: NoSuchMethodError: The method 'signIn' was called on null.
I/flutter (10611): Receiver: null
I/flutter (10611): Tried calling: signIn("IDが表示されている", "<PWが表示されている>")
E/flutter (10611): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: Class 'NoSuchMethodError' has no instance getter 'message'.
E/flutter (10611): Receiver: Instance of 'NoSuchMethodError'
E/flutter (10611): Tried calling: message
E/flutter (10611): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
E/flutter (10611): #1      _LoginSignupPageState.validateAndSubmit.<anonymous closure> (package:flutter_app/login_signup_page.dart:78:29)
E/flutter (10611): #2      State.setState (package:flutter/src/widgets/framework.dart:1148:30)
E/flutter (10611): #3      _LoginSignupPageState.validateAndSubmit (package:flutter_app/login_signup_page.dart:76:9)
E/flutter (10611): #4      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:706:14)
E/flutter (10611): #5      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:789:36)
E/flutter (10611): #6      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (10611): #7      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486:11)
E/flutter (10611): #8      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:264:5)
E/flutter (10611): #9      BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:236:7)
E/flutter (10611): #10     GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter (10611): #11     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222:20)
E/flutter (10611): #12     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter (10611): #13     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (10611): #14     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (10611): #15     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (10611): #16     _rootRunUnary (dart:async/zone.dart:1138:13)
E/flutter (10611): #17     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter (10611): #18     _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
E/flutter (10611): #19     _invoke1 (dart:ui/hooks.dart:273:10)
E/flutter (10611): #20     _dispatchPointerDataPacket (dart:ui/hooks.dart:182:5)
void main() {
  // 省略
}

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
        // 省略,
        home: RootPage(auth: Auth()));
  }
}
class RootPage extends StatefulWidget {
  RootPage({this.auth});

 //The auth instance unique?
  final BaseAuth auth;
  State<StatefulWidget> createState() => _RootPageState();
}

class _RootPageState extends State<RootPage> {
  AuthStatus authStatus = AuthStatus.NOT_DETERMINED;
  String _userId = "";

  void initState() {
    super.initState();
    widget.auth.getCurrentUser().then((user) {
      setState(() {
        if (user != null) {
          _userId = user?.uid;
        }
        authStatus =
            user?.uid == null ? AuthStatus.NOT_LOGGED_IN : AuthStatus.LOGGED_IN;
      });
    });
  }

  void loginCallback() {
  // 省略
  }

 //★Is this process properly called?
  void logoutCallback() {
    setState(() {
      authStatus = AuthStatus.NOT_LOGGED_IN;
      _userId = "";
    });
  }

  Widget buildWaitingScreen() {
    return Scaffold(
      // 省略
    );
  }

  Widget build(BuildContext context) {
    switch (authStatus) {
      case AuthStatus.NOT_DETERMINED:
        return buildWaitingScreen();
        break;
      case AuthStatus.NOT_LOGGED_IN:
        return LoginSignupPage(
          auth: widget.auth,
          loginCallback: loginCallback,
        );
        break;
      case AuthStatus.LOGGED_IN:
        if (_userId.length > 0 && _userId != null) {
          return HomePage(
            userId: _userId,
            auth: widget.auth,
            logoutCallback: logoutCallback,
          );
        } else
          return buildWaitingScreen();
        break;
      default:
        return buildWaitingScreen();
    }
  }
}

0 个答案:

没有答案