Open asbah007 opened 3 years ago
Example are not null safe, you have to change it to nullable type by adding ?
where the error is occurred.
try
/// Donut chart example. This is a simple pie chart with a hole in the middle.
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:flutter/material.dart';
class DonutPieChart extends StatelessWidget {
final List<charts.Series<LinearSales, int>> seriesList;
final bool? animate;
DonutPieChart(this.seriesList, {this.animate});
/// Creates a [PieChart] with sample data and no transition.
factory DonutPieChart.withSampleData() {
return new DonutPieChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
);
}
@override
Widget build(BuildContext context) {
return new charts.PieChart<int>(
seriesList,
animate: animate,
// Configure the width of the pie slices to 60px. The remaining space in
// the chart will be left as a hole in the center.
defaultRenderer: new charts.ArcRendererConfig(arcWidth: 60),
);
}
/// Create one series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final data = [
new LinearSales(0, 100),
new LinearSales(1, 75),
new LinearSales(2, 25),
new LinearSales(3, 5),
];
return [
new charts.Series<LinearSales, int>(
id: 'Sales',
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: data,
)
];
}
}
/// Sample linear data type.
class LinearSales {
final int year;
final int sales;
LinearSales(this.year, this.sales);
}
Using Flutter 2.5, I still experience this issue whenever I specify a defaultRenderer. Removal of the renderer line will draw a basic pie chart, but I am unable to produce a gauge variation.
UPDATE: Solution found under Issue651, whereby I needed to specify the generic type, in order to use defaultRenderer correctly:
charts.PieChart<String>( ...
try
/// Donut chart example. This is a simple pie chart with a hole in the middle. import 'package:charts_flutter/flutter.dart' as charts; import 'package:flutter/material.dart'; class DonutPieChart extends StatelessWidget { final List<charts.Series<LinearSales, int>> seriesList; final bool? animate; DonutPieChart(this.seriesList, {this.animate}); /// Creates a [PieChart] with sample data and no transition. factory DonutPieChart.withSampleData() { return new DonutPieChart( _createSampleData(), // Disable animations for image tests. animate: false, ); } @override Widget build(BuildContext context) { return new charts.PieChart<int>( seriesList, animate: animate, // Configure the width of the pie slices to 60px. The remaining space in // the chart will be left as a hole in the center. defaultRenderer: new charts.ArcRendererConfig(arcWidth: 60), ); } /// Create one series with sample hard coded data. static List<charts.Series<LinearSales, int>> _createSampleData() { final data = [ new LinearSales(0, 100), new LinearSales(1, 75), new LinearSales(2, 25), new LinearSales(3, 5), ]; return [ new charts.Series<LinearSales, int>( id: 'Sales', domainFn: (LinearSales sales, _) => sales.year, measureFn: (LinearSales sales, _) => sales.sales, data: data, ) ]; } } /// Sample linear data type. class LinearSales { final int year; final int sales; LinearSales(this.year, this.sales); }
it gives me also the errors and error is
type 'ArcRenderer
copied this code from graph example and got this error