I want to display a chart that retrieve from firebase firestore but its says that
The argument type ‘Future<List<PieChartSectionData>>’ can’t be assigned to the parameter type ‘List<PieChartSectionData>?’ on the line sections: showingSections();
. Here are my codes,
children: <Widget>[
const SizedBox(height: 18),
Expanded(
child: AspectRatio(
aspectRatio: 1,
child: PieChart(
PieChartData(
pieTouchData: PieTouchData(
touchCallback:
(FlTouchEvent event,
pieTouchResponse) {},
),
borderData: FlBorderData(
//show: false,
),
sectionsSpace: 0,
centerSpaceRadius: 40,
sections: showingSections(), // this is the error //
),
),
),
),
Column(
mainAxisAlignment:
MainAxisAlignment.end,
crossAxisAlignment:
CrossAxisAlignment.start,
children: const <Widget>[
Indicator(
color: Colors.blue,
text: 'Fiest',
isSquare: true,
),
],
),
],
this is my function,
Future<List<PieChartSectionData>> showingSections() async {
int count = await subuhPrayedOnTime();
int count2 = await subuhPrayedLate();
double percentage1 = count * 0.4;
double percentage2 = count2 * 0.10;
return [
PieChartSectionData(
color: Colors.blueAccent,
value: percentage1,
title: '${percentage1.toStringAsFixed(0)}%',
radius: 60,
titleStyle: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.black,
//shadows: shadows,
),
),
PieChartSectionData(
color: Colors.blueAccent,
value: percentage2,
title: '${percentage2.toStringAsFixed(0)}%',
radius: 60,
titleStyle: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.black,
//shadows: shadows,
),
),
];
}
2
Answers
Try changing return type of the function from
To
showingSections
is a future method, you need to await/FutureBuilder to fetch data.For your case, create a future on state class[if stateFullWidget].
and use like
Find more about FutureBuilder