【发布时间】:2020-11-23 10:50:10
【问题描述】:
我最近开始使用 Flutter。 我的应用程序运行一个 sqflite 数据库,我想从中获取所有数据并将其显示在我的应用程序的行小部件中。
我知道如何获取数据,也知道如何构建小部件。 我很困惑,我不知道如何将从数据库中获取的数据转换为列表(我可以使用它来构建我的小部件)。
所以我得到了未来清单,但我需要清单饮料
看看:
我的对象:
class Drink {
int id;
String time;
int amount;
Drink({this.id, this.time, this.amount});
}
数据库:
Future _onCreate(Database db, int version) async {
await db.execute('''
CREATE TABLE $table (
$columnId INTEGER PRIMARY KEY,
$columnTime TEXT NOT NULL,
$columnAmount INTEGER NOT NULL
)
''');
}
我如何获得输出:
Future<List> raw() async {
Database db = await instance.database;
var dbClient = await db;
var result = await dbClient.rawQuery("SELECT * FROM $table");
List<Map<String, dynamic>> r = result.toList();
return r;
}
【问题讨论】:
-
这能回答你的问题吗? What is a Future and how do I use it?