Firebase 超时函数仍然执行该操作
我正在尝试创建一种方法,用户可以使用附加的超时功能更改其Firebase 超时函数仍然执行该操作,firebase,flutter,firebase-authentication,future,Firebase,Flutter,Firebase Authentication,Future,我正在尝试创建一种方法,用户可以使用附加的超时功能更改其firebase\u身份验证显示名称: Future<void> changeDisplayName({String name}) async { try { await _auth.currentUser .updateProfile(displayName: name) .timeout(Duration(seconds: 10)) .then(
firebase\u身份验证显示名称
:
Future<void> changeDisplayName({String name}) async {
try {
await _auth.currentUser
.updateProfile(displayName: name)
.timeout(Duration(seconds: 10))
.then((value) => _createSnackbar(
'Update Successfull', 'Your new display name is $name'));
} on TimeoutException {
Navigator.pop();
_createSnackbar(
'Timeout Exception', 'Operation stopped.');
} catch (e) {
_createSnackbar('Error Occurred', '${e.toString()}');
}
}
futureChangeDisplayName({String name})异步{
试一试{
等待_auth.currentUser
.updateProfile(显示名称:名称)
.超时(持续时间(秒:10))
.then((值)=>\u createSnackbar(
“更新成功”,“您的新显示名称为$name”);
}论时间例外{
Navigator.pop();
_创建snackbar(
“超时异常”,“操作已停止”。);
}捕获(e){
_createSnackbar('发生错误','${e.toString()}');
}
}
我的目的是在抛出超时异常时,完全停止操作。但即使引发超时异常,
配置文件更新仍在超时后完成。调用timeout时如何避免执行该操作?无法取消更新配置文件
操作。一旦您进行了方法调用,您必须等待它完成,然后调用,或者catch
,以确定其结果
如果您试图处理用户不在网络上的情况,您可能希望在调用API之前检测该情况。但就我个人而言,我只想把实际情况告诉用户:“这比预期的时间要长,你可能想稍后再试。”哦,这样的方法就足够了。对于其他Firebase操作,例如updatePassword
| |使用凭据重新验证是否也是如此?谢谢你的澄清。