如何修复在Flutter中创建甜甜圈饼图时的错误



我在flutter中创建甜甜圈饼图时出错。我可以显示常规饼图,但当我添加时:

defaultRenderer: charts.ArcRendererConfig(arcWidth: 25)

我的饼图将消失,并得到以下错误:

键入'List<ArcRendererElement>'不是类型"List<ArcRendererElement>?'型铸

知道是什么导致了这个问题吗?

class Donut extends StatelessWidget {
const Donut({Key? key}) : super(key: key);
static final List<WorldPopulation> populationData = [
WorldPopulation('2010', 1000, Colors.grey),
WorldPopulation('AS', 2000, Colors.black),
WorldPopulation('NA', 3000, Colors.red),
WorldPopulation('EU', 4000, Colors.blue),
WorldPopulation('OC', 5000, Colors.green),
WorldPopulation('SACA', 6000, Colors.orange),
WorldPopulation('2016', 7000, Colors.purple),
WorldPopulation('2017', 8000, Colors.yellow),
WorldPopulation('2018', 9000, Colors.pink),
];
@override
Widget build(BuildContext context) {
List<charts.Series<WorldPopulation, String>> series = [
charts.Series(
data: populationData,
id: "World Population",
domainFn: (WorldPopulation pops, _) => pops.year,
measureFn: (WorldPopulation pops, _) => pops.population,
colorFn: (WorldPopulation pops, _) => charts.ColorUtil.fromDartColor(pops.barColor))
];
return Scaffold(
backgroundColor: Colors.grey.shade200,
body: Center(
child: Padding(
padding: const EdgeInsets.all(10),
child: Container(
height: MediaQuery.of(context).size.height / 2,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10)),
child: charts.PieChart(
series,
defaultRenderer: charts.ArcRendererConfig(arcWidth: 50),
)),
),
),
);
}
}
class WorldPopulation {
final String year;
final int population;
final Color barColor;
WorldPopulation(this.year, this.population, this.barColor);
}

我发现了一个相关的问题:发布链接

您也可以尝试将对象强制转换为List<List<ArcRendererElement>?

相关内容

  • 没有找到相关文章

最新更新