【问题标题】:How to fix "A value of type '(FirebaseUser) → Null' can't be assigned to a variable of type '(AuthCredential) → void'."?如何解决“无法将类型为'(FirebaseUser)→Null'的值分配给类型为'(AuthCredential)→void'的变量。”?
【发布时间】:2019-10-19 09:54:03
【问题描述】:

我正在尝试在我的应用程序上设置电话身份验证,但遇到此错误“无法将类型 '(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);
 }

【问题讨论】:

    标签: firebase flutter firebase-authentication


    【解决方案1】:

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

    应该是这样的:

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

    【讨论】:

    • Valeu Hugo, realmente funcionou!!
    猜你喜欢
    • 1970-01-01
    • 2020-02-01
    • 2020-01-10
    • 2016-12-24
    • 2020-02-19
    • 1970-01-01
    • 1970-01-01
    • 2022-11-01
    • 2021-04-04
    相关资源
    最近更新 更多