[英]Convert Future<List> of custom object in list of object
i need support on a problem.我需要一个问题的支持。 I have a method of my DatabaseHelper that takes care of recovering users from my database created with SQLite.我的 DatabaseHelper 有一个方法,它负责从使用 SQLite 创建的数据库中恢复用户。 So I created a class called DatabaseUserHelper that takes care of retrieving information.所以我创建了一个名为 DatabaseUserHelper 的 class 负责检索信息。 Here is the method of my class:这是我的class的方法:
Future<List> getAllUser() async {
var dbClient = await db;
var result = await dbClient.query(tableUser, columns: [columnId, columnNome, columnCognome, columnUsername]);
return result.toList();
}
My requirement is to convert the result of this method into a normal list.我的要求是将此方法的结果转换为普通列表。 Here is an example of what I would like to do with Java.这是我想用 Java 做的一个例子。
List <User> listUser = getAllUser ()
Unfortunately, however, every time I try to make this conversion I always get an error.然而不幸的是,每次我尝试进行这种转换时,我总是会出错。
Is there anything I can do?有什么我可以做的吗? Thank you all谢谢你们
You should use await
keyword before calling the function getAllUser like below:您应该在调用 function getAllUser 之前使用await
关键字,如下所示:
List<User> listUser = await getAllUser();
It is because your function has 'Future' keyword which means the result will be available sometime in the future .这是因为您的 function 具有“未来”关键字,这意味着结果将在未来某个时间可用。 So, you should wait a bit.所以,你应该稍等片刻。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.