Flutter应用程序在Firebase电话身份验证时崩溃

时间:2020-07-27 09:22:38

标签: firebase flutter firebase-authentication

我正在开发一个Flutter应用程序,试图在其中使用Firebase电话身份验证对用户进行身份验证。

根据Firebase政策,我们在调试时无法获取身份验证代码,因此我必须使用预定义的代码将电话号码添加到Firebase控制台中。

现在,它在调试时可以正常工作,但是当我在Google Play服务验证电话的发布模式下使用它时,我的应用程序崩溃了。但是,当我再次打开该应用程序时,它已通过身份验证并且可以正常工作。如何调试此崩溃?

这是我的代码

  signInWithPhone(String phone) {
    _authStatus = AuthStatus.Authenticating;
    notifyListeners();
    try {
      _auth.verifyPhoneNumber(
          phoneNumber: phone,
          timeout: Duration(seconds: 60),
          verificationCompleted: (AuthCredential _authCredential) {
            _getFirebaseUser(_authCredential);
            print("verificationCompleted: ${_authCredential.providerId}");
          },
          verificationFailed: (AuthException authException) {
            print("Auth Failed: ${authException.message}");
            _authStatus = AuthStatus.Uninitialized;
            notifyListeners();
          },
          codeSent: (String verificationId, [int forceResendingToken]) {
            this.verificationId = verificationId;
            print("Code Sent: $verificationId");
            _authStatus = AuthStatus.CodeSent;
            notifyListeners();
          },
          codeAutoRetrievalTimeout: (String verificationId) {
            this.verificationId = verificationId;
            print("Actual Code: $verificationId");
          });
    } catch (e) {
      print(e.toString());
    }
  }


  void _getFirebaseUser(AuthCredential authCredential) async {
    try {
      AuthResult authResult =
          await _auth.signInWithCredential(authCredential).catchError((e) {
        print(e.toString());
      });
      _firebaseUser = authResult.user;
      notifyListeners();
    } catch (e) {
      print(e.toString());
      _authStatus = AuthStatus.Uninitialized;
      notifyListeners();
    }
  }

0 个答案:

没有答案