【发布时间】:2021-02-19 16:54:05
【问题描述】:
我有一个调用Future<bool> 函数的函数:
bool checkId(String id, context) {
bool ret;
checkMissingId(id, context).then((value) => ret = value);
return ret;
那叫:
Future<bool> checkMissingId(String id, context) async {
String str = id.toLowerCase();
String letter = str[0];
if (checkStr(id, letter, str) == false)
return false; //checks some rules on strings
else {
try {
var data = await FirebaseFirestore.instance
.collection("ids/tabs/" + letter)
.doc(str)
.get();
if (data.exists) {
return false;
} else
return true;
} catch (e) {
await showErrDialog(context, e.code);
return false;
}
}
}
ret 返回null,而不是布尔值。
编辑:checkId 的类型必须是 bool,而不是 Future<bool>
【问题讨论】:
标签: flutter dart asynchronous