I recently started with Flutter. My App runs a sqflite database and I want to get all the data out of it and show it in a Row Widget in my App.
I know how to get the data and I know how to build the Widgets. I´m so confused, I have no idea how to convert the data that I get from the database to a List (with that I could build my widgets).
So I get Future List but I need List Drink
Just look:
My Object:
class Drink {
int id;
String time;
int amount;
Drink({this.id, this.time, this.amount});
}
Database:
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
)
''');
}
How I get the output:
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;
}