Reputation: 527
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);
}
Upvotes: 4
Views: 2790
Reputation: 8447
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");
};
Upvotes: 5