如何解决“不能将类型为((FirebaseUser)→空”的值分配给类型为((AuthCredential)→空”的变量。”

时间:2019-06-03 20:34:03

标签: firebase flutter firebase-authentication

我正在尝试在我的应用程序上设置电话身份验证,但我被此错误困扰:“无法将类型'(FirebaseUser)→Null'的值分配给类型'(AuthCredential)→void '。”。关于如何解决它的任何想法?预先感谢您的帮助!

class _AuthScreenState extends State<AuthScreen> {
 String phoneNo;
 String smsCode;
 String verificationId;

Future<void> verifyPhone() async {

final PhoneCodeAutoRetrievalTimeout autoRetrieve =(String verId) {
  this.verificationId = verId;

};

final PhoneCodeSent smsCodeSent = (String verId, [int 
forceCodeResend]){
  this.verificationId = verId;
};

final PhoneVerificationCompleted verifiedSuccess = (FirebaseUser 
user) {
  print("Verificado");

};

final PhoneVerificationFailed verifiedFailed = (AuthException 
exception) {
  print("${exception.message}");

};

await FirebaseAuth.instance.verifyPhoneNumber(
    phoneNumber: this.phoneNo,
    timeout: const Duration(seconds: 5),
    verificationCompleted: verifiedSuccess,
    verificationFailed: verifiedFailed,
    codeSent: smsCodeSent,
    codeAutoRetrievalTimeout: autoRetrieve);
 }

1 个答案:

答案 0 :(得分:0)

类型PhoneVerificationCompleted用于接收FirebaseUser并返回void,但是在某些最新更新中,这种情况发生了变化。现在它收到AuthCredential。只需在分配给变量verifiedSuccess的方法中更改类型。

它应该像这样:

final PhoneVerificationCompleted verifiedSuccess = (AuthCredential credential) {
  print("Verificado");
};