我正在尝试在我的应用程序上设置电话身份验证,但我被此错误困扰:“无法将类型'(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);
}
答案 0 :(得分:0)
类型PhoneVerificationCompleted
用于接收FirebaseUser
并返回void
,但是在某些最新更新中,这种情况发生了变化。现在它收到AuthCredential
。只需在分配给变量verifiedSuccess
的方法中更改类型。
它应该像这样:
final PhoneVerificationCompleted verifiedSuccess = (AuthCredential credential) {
print("Verificado");
};