【发布时间】:2021-03-23 16:27:23
【问题描述】:
我在获取值形式函数 Future 时遇到问题
我下面有一个函数
Future<bool> checkstr(String str) async {
bool result = await check(str);
if (result == null) {
return false;
} else {
return true;
}
}
当我得到并检查值遇到错误时
Expanded(
child: model.isBusy
? CircularProgressIndicator()
: ListView.builder(
itemBuilder: (BuildContext context, int index) {
return ListTile(
model.checkstr(str) //<------ error this line
? title: Text('true')
: title: Text('false'),
}),
),
错误
Flutter Error: A value of type 'Future<bool>' can't be assigned to a variable of type 'bool'
请帮帮我。
【问题讨论】:
-
您不能直接调用该方法,因为您需要等待结果。尝试使该方法不再是未来或在另一个地方进行调用并在使用该值之前等待结果。
-
发布您的
check(str)功能。是未来吗?你为什么要等它?根据您的回答,您主要有两种解决方案之一。
标签: flutter dart boolean future getvalue