Reputation: 336
I wanna implement firebase auth method but it want me recaptcha when I pass recaptcha I face to this problem
E/flutter (19828): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method 'delegateFor' was called on null.
E/flutter (19828): Receiver: null
E/flutter (19828): Tried calling: delegateFor(container: "recptcha", onError: Closure: (FirebaseAuthException) => Null, onExpired: Closure: () => void, onSuccess: Closure: () => void, size: Instance of 'RecaptchaVerifierSize', theme: Instance of 'RecaptchaVerifierTheme')
Here is my code :
FirebaseAuth.instance.signInWithPhoneNumber(
phoneNumber,
RecaptchaVerifier(
container: 'recptcha',
onError: (e) {
print(e);
},
onExpired: () => print("Expired"),
onSuccess: () => print("Success"),
size: RecaptchaVerifierSize.compact,
theme: RecaptchaVerifierTheme.light,
),
);
Upvotes: 2
Views: 2993
Reputation: 943
var recaptchaVerifier = RecaptchaVerifier(
container: null,
size: RecaptchaVerifierSize.compact,
theme: RecaptchaVerifierTheme.dark,
onSuccess: () async {
print('reCAPTCHA Completed!');
setState(() {
currentInput = "otp";
_isLoading = false;
});
},
onError: (FirebaseAuthException error) async {
print("error");
print(error);
setState(() {
_isLoading = false;
});
_scaffoldKey.currentState
.showSnackBar(SnackBar(content: Text(error.message)));
},
onExpired: () async {
print('reCAPTCHA Expired!');
setState(() {
_isLoading = false;
});
},
);
```
await _auth.signInWithPhoneNumber(phoneController.text, recaptchaVerifier).then((confirmationResult) {
// SMS sent. Prompt user to type the code from the message, then sign the
// user in with confirmationResult.confirm(code).
setState(() {
verificationId = confirmationResult.verificationId;
});
}).catchError((error) {
print(error);
});
```
Upvotes: 3