i work with an exist sqlite database, and i want to display a random row from it. i followed this steps , but it display the row with the name of the column and the brakets.
this is the code i used :
var name;
void _query() async {
Database db = await DatabaseHelper.instance.database;
List<Map> result = await db.rawQuery('SELECT content FROM $table ORDER BY random() LIMIT 1');
setState(() {
result.forEach((row){
print(row);
name= result;
});
});
}
in the builder, i use this :
Container(
child: Text('${name}'),
),
RaisedButton(
child: Text('Generate another'),
onPressed: (){
_query()
;},
),
the result in terminal {content:james}
and in the emulator [{content:james}]
i want to display just : james
thank you
result
is a List
of Map
so you can use first
& correct key to access the desired result.
setState(() {
name = result.first['content']; // james
});