如何解决“无法将类型'(FirebaseUser)→空'的值分配给类型'(AuthCredential)→空'的变量". [英] How to fix "A value of type '(FirebaseUser) → Null' can't be assigned to a variable of type '(AuthCredential) → void'."?

查看:81
本文介绍了如何解决“无法将类型'(FirebaseUser)→空'的值分配给类型'(AuthCredential)→空'的变量".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to set up phone authentication on my app but I got stuck with this error "A value of type '(FirebaseUser) → Null' can't be assigned to a variable of type '(AuthCredential) → void'.". Any Idea on how to fix it? Thanks in advance for your help!

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);
 }

推荐答案

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

The type PhoneVerificationCompleted used to receive FirebaseUser and return void, but this changed in some of the latest updates. Now it receives AuthCredential. Just change the type in the method that you assigned to the variable verifiedSuccess.

它应该看起来像这样:

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

这篇关于如何解决“无法将类型'(FirebaseUser)→空'的值分配给类型'(AuthCredential)→空'的变量".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆