【发布时间】:2020-05-16 20:34:27
【问题描述】:
我需要检查 .then 函数内设置的变量的值,以便我可以返回不同的小部件,但我不知道。 在 then 之外,存在的值为 false,如果在 the 内部,则为 true。 另外,如果我将返回值放在 .then 中,则返回值为空。 你能帮帮我吗?
Widget build(BuildContext context) {
bool exists;
seEsiste(db, idPaz).then((value) => {
exists = value
});
if (exists) {
return Text("load Text");
}else {
return ZefyrScaffold(
child: ZefyrEditor(
padding: EdgeInsets.all(16.0),
controller: _controller,
focusNode: _focusNode,
),
);
}
}
}
【问题讨论】:
-
根据我的经验 - 只需将底部的所有内容都设置为 async 并在调用时将 await 放入,同时返回
.then之前的部分。
标签: flutter async-await