我无法使用Flutter和fuurebase_auth插件在Firebase上使用电话验证登录

时间:2019-07-04 20:20:10

标签: firebase flutter dart firebase-authentication

我一直在下面收到此错误: 方法'signInWithCredential'在null上调用。

[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: NoSuchMethodError: The method 'signInWithCredential' was called on null.
E/flutter (29053): Receiver: null
E/flutter (29053): Tried calling: signInWithCredential(Instance of 'AuthCredential')
E/flutter (29053): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
E/flutter (29053): #1      _LoginScreenState._signInWithPhoneNumber (package:jollycab_flutter/screens/login_screen.dart:74:43)
E/flutter (29053): <asynchronous suspension>
E/flutter (29053): #2      _LoginScreenState.build.<anonymous closure> (package:jollycab_flutter/screens/login_screen.dart:384:23)
E/flutter (29053): <asynchronous suspension>
E/flutter (29053): #3      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:511:14)
E/flutter (29053): #4      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:566:30)
E/flutter (29053): #5      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:166:24)
E/flutter (29053): #6      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:240:9)
E/flutter (29053): #7      TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:177:9)

我在这里使用flutter团队的代码示例: https://github.com/flutter/plugins/blob/master/packages/firebase_auth/example/lib/signin_page.dart

该代码从第508行开始。由于某些原因,signInWithCredential似乎无法获得所需的内容或不起作用

1 个答案:

答案 0 :(得分:1)

如果使用的是示例,则在代码中的某个位置具有_auth.signInWithCredential且_auth为null,则缺少其初始化。或者您正在使用无效值对其进行初始化(是否为空?)