如何解决'Future<int>' 的实例
Future<int> getCountTodo(int taskId) async {
Database db = await this.db;
List<Map<String,dynamic>> x = await db.rawQuery('SELECT COUNT (*) from $todoTable where taskId=$taskId');
// List<Map<String,dynamic>> x = await db.rawQuery('SELECT COUNT(*),t.title FROM todo_table td,task_table t WHERE t.id=td.taskId GROUP BY taskId');
int result = Sqflite.firstIntValue(x);
print('Todo inside task: $result');
return result;
}
Text (
// '${1}'+" ITEM",DatabaseHelper.instance.getCountTodo(task.tasklist[index].id).toString(),style: TextStyle(
fontSize: 14.0,color: Colors.grey,fontWeight: FontWeight.bold),)
我如何在文本小部件中获得计数结果。我得到了“未来”的实例。
解决方法
最好在这里使用未来的构建器:
FutureBuilder(
future: DatabaseHelper.instance.getCountTodo(task.tasklist[index].id),builder: (BuildContext context,AsyncSnapshot<String> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting: return Text('Loading....');
default:
if (snapshot.hasError)
return Text('Error: ${snapshot.error}');
else if (snapshot.data==null)
return Text('Loading....');
else
return Text('${snapshot.data}');
}
},)
)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。