firebase - method call of another class from a widget supposed to return true, but returns nothing
问题描述
I have this method below which resides in a class, I am trying to call this method from a widget using Authenticate().signInWithPhone, and based on its return value I am supposed to setState of a variable inside of the widget class which in turn changes the screen elements. But when running this code I believe nothing is being run inside of the setState method, because the codeSent variable always has the false value.
class Authenticate {
String verificationId = '';
String phone = '';
bool codeSent = false;
Future<User?> getSessionStatus() async {
return await FirebaseAuth.instance.currentUser;
}
Future<bool> signInWithPhone(String phone, BuildContext context) async {
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: phone,
verificationCompleted: (PhoneAuthCredential credential) async {
await FirebaseAuth.instance.signInWithCredential(credential);
final snackBar = SnackBar(content: Text("Login Success"));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
verificationFailed: (FirebaseAuthException e) {
final snackBar = SnackBar(content: Text("${e.message}"));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
codeSent: (String verificationId, int? resendToken) {
codeSent = true;
verificationId = verificationId;
},
codeAutoRetrievalTimeout: (String verificationId) {
verificationId = verificationId;
},
timeout: Duration(seconds: 60),
);
return codeSent;
}
}
Now I am calling this method from a stateful widget.
ElevatedButton(
onPressed: () {
//verifyPhone();
Authenticate()
.signInWithPhone(phone, context)
.then((result) => {
print(result),
setState(() {
codeSent = result;
}),
print(result),
});
},
child: Text('Verify'),
)
解决方案
推荐阅读
- python - python xlwings模块错误:OSError:[WinError -2147467259]未指定错误
- azure - azure devops 管道 CopyFiles@2 任务从代理 A 复制文件,但 DownloadBuildArtifacts@0 将文件下载到代理 B
- vue.js - 如何在 Vue 项目中正确构建组件?
- macos - 当应用程序在 mac 中聚焦时触发苹果脚本/自动器
- r - R:从带有循环的表中计算
- stripe-payments - STRIPE 错误:要使用 Checkout,您必须在 https://dashboard.stripe.com/account 设置帐户或公司名称
- flutter - 我已经用 api 的 listview.builder 创建了一个卡片列表。现在我想在点击一张卡片时更改墨水池点击中的卡片颜色
- python - 模块“matplotlib.pyplot”没有属性“补丁”
- python - mod_wsgi-express 模块配置问题
- elasticsearch - 如何在 Kibana Dashboard 中禁用弹性用户访问