我想显示从Firebase Firestore检索的图表,但它显示
参数类型'Future〈List〉'不能分配给行部分上的参数类型'List?':显示截面();
这是我的密码
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,
),
],
),
],
这是我的职责
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条答案
按热度按时间jhkqcmku1#
尝试将函数的返回类型从
至
30byixjq2#
showingSections
是将来的方法,您需要等待/FutureBuilder提取数据。对于您的情况,在状态类[if stateFullWidget]上创建一个future。
并使用类似
了解更多关于FutureBuilder的信息