如何解决“无法将类型'(FirebaseUser)→空'的值分配给类型'(AuthCredential)→空'的变量".

如何解决“无法将类型'(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");
};