flutter_circular_chart/examples/animated_pie_chart_example.dart

85 lines
2.6 KiB
Dart
Raw Normal View History

2017-11-03 01:57:39 +00:00
import 'package:flutter/material.dart';
2021-03-08 17:54:34 +00:00
import 'package:flutter_circular_chart_two/flutter_circular_chart_two.dart';
2017-11-03 01:57:39 +00:00
void main() {
2021-03-08 17:37:23 +00:00
runApp(MaterialApp(
home: AnimatedPieChartExample(),
2017-11-03 01:57:39 +00:00
));
}
final List<List<CircularStackEntry>> _quarterlyProfitPieData = [
<CircularStackEntry>[
2021-03-08 17:37:23 +00:00
CircularStackEntry(
2017-11-03 01:57:39 +00:00
<CircularSegmentEntry>[
2021-03-08 17:37:23 +00:00
CircularSegmentEntry(500.0, Colors.red[200], rankKey: 'Q1'),
CircularSegmentEntry(1000.0, Colors.green[200], rankKey: 'Q2'),
CircularSegmentEntry(2000.0, Colors.blue[200], rankKey: 'Q3'),
CircularSegmentEntry(1000.0, Colors.yellow[200], rankKey: 'Q4'),
2017-11-03 01:57:39 +00:00
],
rankKey: 'Quarterly Profits',
),
],
<CircularStackEntry>[
2021-03-08 17:37:23 +00:00
CircularStackEntry(
2017-11-03 01:57:39 +00:00
<CircularSegmentEntry>[
2021-03-08 17:37:23 +00:00
CircularSegmentEntry(1500.0, Colors.red[200], rankKey: 'Q1'),
CircularSegmentEntry(750.0, Colors.green[200], rankKey: 'Q2'),
CircularSegmentEntry(2000.0, Colors.blue[200], rankKey: 'Q3'),
CircularSegmentEntry(1000.0, Colors.yellow[200], rankKey: 'Q4'),
2017-11-03 01:57:39 +00:00
],
rankKey: 'Quarterly Profits',
),
],
<CircularStackEntry>[
2021-03-08 17:37:23 +00:00
CircularStackEntry(
2017-11-03 01:57:39 +00:00
<CircularSegmentEntry>[
2021-03-08 17:37:23 +00:00
CircularSegmentEntry(1800.0, Colors.red[200], rankKey: 'Q1'),
CircularSegmentEntry(2900.0, Colors.green[200], rankKey: 'Q2'),
CircularSegmentEntry(4000.0, Colors.blue[200], rankKey: 'Q3'),
CircularSegmentEntry(7000.0, Colors.yellow[200], rankKey: 'Q4'),
2017-11-03 01:57:39 +00:00
],
rankKey: 'Quarterly Profits',
),
],
];
class AnimatedPieChartExample extends StatefulWidget {
@override
2021-03-08 17:37:23 +00:00
_AnimatedPieChartExampleState createState() => _AnimatedPieChartExampleState();
2017-11-03 01:57:39 +00:00
}
class _AnimatedPieChartExampleState extends State<AnimatedPieChartExample> {
2021-03-08 17:37:23 +00:00
final GlobalKey<AnimatedCircularChartState> _chartKey = GlobalKey<AnimatedCircularChartState>();
2017-11-03 01:57:39 +00:00
final _chartSize = const Size(300.0, 300.0);
int sampleIndex = 0;
void _cycleSamples() {
setState(() {
sampleIndex++;
List<CircularStackEntry> data = _quarterlyProfitPieData[sampleIndex % 3];
_chartKey.currentState.updateData(data);
});
}
@override
Widget build(BuildContext context) {
2021-03-08 17:37:23 +00:00
return Scaffold(
appBar: AppBar(
2017-11-03 01:57:39 +00:00
title: const Text('Quarterly Profit'),
),
2021-03-08 17:37:23 +00:00
body: Center(
child: AnimatedCircularChart(
2017-11-03 01:57:39 +00:00
key: _chartKey,
size: _chartSize,
initialChartData: _quarterlyProfitPieData[0],
chartType: CircularChartType.Pie,
),
),
2021-03-08 17:37:23 +00:00
floatingActionButton: FloatingActionButton(
child: Icon(Icons.refresh),
2017-11-03 01:57:39 +00:00
onPressed: _cycleSamples,
),
);
}
}