1

I'm getting an error when trying to create a donut pie chart in flutter. I can get the regular pie chart to show up but when I add:

defaultRenderer: charts.ArcRendererConfig(arcWidth: 25)

My pie chart will disappear and get the following error:

type 'List<ArcRendererElement>' is not a subtype of type 'List<ArcRendererElement>?' in type cast

Any idea whats causing this issue?

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);
}
julemand101
  • 28,470
  • 5
  • 52
  • 48
CodeZer
  • 33
  • 1
  • 4

1 Answers1

0

I found a related Issue for this: Issue Link

You can also try to cast your object as List<List<ArcRendererElement>?

jxstxn __
  • 97
  • 8