2017-11-03 11:45:27 +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 11:45:27 +00:00
|
|
|
import 'dart:math' as Math;
|
|
|
|
|
|
|
|
import 'color_palette.dart';
|
|
|
|
|
|
|
|
void main() {
|
2021-03-08 17:37:23 +00:00
|
|
|
runApp(MaterialApp(
|
|
|
|
home: RandomizedRadialChartExample(),
|
2017-11-03 11:45:27 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
class RandomizedRadialChartExample extends StatefulWidget {
|
|
|
|
@override
|
2021-03-08 17:37:23 +00:00
|
|
|
_RandomizedRadialChartExampleState createState() => _RandomizedRadialChartExampleState();
|
2017-11-03 11:45:27 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 17:37:23 +00:00
|
|
|
class _RandomizedRadialChartExampleState extends State<RandomizedRadialChartExample> {
|
|
|
|
final GlobalKey<AnimatedCircularChartState> _chartKey = GlobalKey<AnimatedCircularChartState>();
|
2017-11-03 11:45:27 +00:00
|
|
|
final _chartSize = const Size(300.0, 300.0);
|
2021-03-08 17:37:23 +00:00
|
|
|
final Math.Random random = Math.Random();
|
2017-11-03 11:45:27 +00:00
|
|
|
List<CircularStackEntry> data;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
2018-03-21 00:11:02 +00:00
|
|
|
super.initState();
|
2017-11-03 11:45:27 +00:00
|
|
|
data = _generateRandomData();
|
|
|
|
}
|
|
|
|
|
|
|
|
double value = 50.0;
|
|
|
|
|
|
|
|
void _randomize() {
|
|
|
|
setState(() {
|
|
|
|
data = _generateRandomData();
|
|
|
|
_chartKey.currentState.updateData(data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
List<CircularStackEntry> _generateRandomData() {
|
|
|
|
int stackCount = random.nextInt(10);
|
2021-03-08 17:37:23 +00:00
|
|
|
List<CircularStackEntry> data = List.generate(stackCount, (i) {
|
2017-11-03 11:45:27 +00:00
|
|
|
int segCount = random.nextInt(10);
|
2021-03-08 17:37:23 +00:00
|
|
|
List<CircularSegmentEntry> segments = List.generate(segCount, (j) {
|
2017-11-03 11:45:27 +00:00
|
|
|
Color randomColor = ColorPalette.primary.random(random);
|
2021-03-08 17:37:23 +00:00
|
|
|
return CircularSegmentEntry(random.nextDouble(), randomColor);
|
2017-11-03 11:45:27 +00:00
|
|
|
});
|
2021-03-08 17:37:23 +00:00
|
|
|
return CircularStackEntry(segments);
|
2017-11-03 11:45:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-03-08 17:37:23 +00:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2017-11-03 11:45:27 +00:00
|
|
|
title: const Text('Randomized radial data'),
|
|
|
|
),
|
2021-03-08 17:37:23 +00:00
|
|
|
body: Center(
|
|
|
|
child: AnimatedCircularChart(
|
2017-11-03 11:45:27 +00:00
|
|
|
key: _chartKey,
|
|
|
|
size: _chartSize,
|
|
|
|
initialChartData: data,
|
|
|
|
chartType: CircularChartType.Radial,
|
|
|
|
),
|
|
|
|
),
|
2021-03-08 17:37:23 +00:00
|
|
|
floatingActionButton: FloatingActionButton(
|
2017-11-03 11:45:27 +00:00
|
|
|
onPressed: _randomize,
|
|
|
|
child: const Icon(Icons.refresh),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|