firebase - Flutter:如何为 firebase auth 插件实现 recaptcha
问题描述
我想实现firebase auth方法但是当我通过recaptcha时它想要我recaptcha我面临这个问题
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')
这是我的代码:
FirebaseAuth.instance.signInWithPhoneNumber(
phoneNumber,
RecaptchaVerifier(
container: 'recptcha',
onError: (e) {
print(e);
},
onExpired: () => print("Expired"),
onSuccess: () => print("Success"),
size: RecaptchaVerifierSize.compact,
theme: RecaptchaVerifierTheme.light,
),
);
解决方案
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);
});
```
推荐阅读
- python-3.x - 为什么'is'运算符在 Python - 3.6.8 中显示不同的结果?
- javascript - 如何通过 Python 使用 Selenium 将日期作为文本直接发送到具有只读属性的日历控件?
- serialization - 使用 json_serializable 序列化对象列表而不创建额外的类
- java - 使用 Stream.ofNullable 处理可为空的列表是否是不好的做法
- javascript - 变换图像上的无限动画
- python - Lambda 函数减去 x 和前一个元素
- python - 如何从分类器.predict_proba() 输出中获取前 n 个预测标签?
- android - 我如何从点击项目中的firebase数据库中获取子值
- php - 检查输入框中的字符串是否等于 SQL SERVER、PHP 中的 varbinary(max) | SQL 服务器 2012
- makefile - (Makefile 错误:*** 缺少分隔符)以下 makefile 在我的本地 IDE 中工作正常,但在 Putty 客户端中运行时失败