I am trying to get data from sqflite using FutureBuilder Here is my Code :
Function To get charts from Sqflite
getCharts(table, column_name, ids) async {
var conn = await database;
// var li = [];
var data = await conn.query(table,
where: "indicator_id IN (${List.filled(ids.length, '?').join(',')})",
whereArgs: ids);
return data;
}
This Function Returns:
[
{
id: 1, indicator_id: 1,
label: Percentage of population with access to electricity,
np: 89.9,
p1: 88.5,
p2: 96.3,
p3: 97.4,
p4: 98.9,
p5: 90.8,
p6: 44.9,
p7: 77.1,
chart_type: pie_chart,
name: Access to electricity,
description: Percentage of population with access to electricity
}
]
Function from Chart Service
Future<List<Chart>> getCharts(List<int> ids) async {
var res = await _repository!.getCharts('charts', 'indicator_id', ids);
var mapped = res.map((chart) => new Chart.fromJson(chart)).toList();
print(mapped);
return mapped;
}
This Function Returns:
[Instance of 'Chart']
On The Chart Screen
ChartService _chart2service = ChartService();
Future<List<Chart>>? futureChart;
@override
void initState() {
super.initState();
futureChart = _chart2service.getCharts(this.widget.ids!);
}
But When I try FutureBuilder:
FutureBuilder<List<Chart>>(
future: futureChart,
builder: (context, snapshot) {
print(snapshot.data);
})
snapshot.data is returning null value.