How to fix “A value of type '(FirebaseUser) → Null' can't be assigned to a variable of type '(AuthCredential) → void'.”?

荒凉一梦 提交于 2020-01-04 05:34:07

问题


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

回答1:


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.

It should look like this:

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


来源:https://stackoverflow.com/questions/56434203/how-to-fix-a-value-of-type-firebaseuser-%e2%86%92-null-cant-be-assigned-to-a-varia

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!