以下内容将捕获错误并显示“用户已锁定”。如果我从该部分抛出,我的应用程序将崩溃。如何获取错误并一直传递到onPressed?
Future activate(String uid) {
return _fire.runTransaction((transaction) {
var ref = buildUser(uid);
return transaction.get(ref).then((userDoc) {
var user = Profile.fromJson(userDoc.data);
if (user.isLocked) throw "User is locked";
....
return transaction.update(ref, user.toJson());
}).catchError((onError) {
print(onError);
});
});
它称为onPressed
try {
await api.activate(uid);
} catch (e) {
print('onAction $e');
}