aurcache/frontend/lib/screens/dashboard/components/charts.dart

96 lines
2.8 KiB
Dart

import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
class Chart extends StatefulWidget {
const Chart({
Key? key,
}) : super(key: key);
@override
_ChartState createState() => _ChartState();
}
class _ChartState extends State<Chart> {
int touchedIndex = -1;
@override
Widget build(BuildContext context) {
return SizedBox(
height: 300,
child: AspectRatio(
aspectRatio: 1.3,
child: Row(
children: <Widget>[
const SizedBox(
height: 18,
),
Expanded(
child: AspectRatio(
aspectRatio: 1,
child: PieChart(
PieChartData(
pieTouchData:
PieTouchData(touchCallback: (pieTouchResponse, touchresponse) {
setState(() {
// final desiredTouch = pieTouchResponse.touchInput
// is! PointerExitEvent &&
// pieTouchResponse.touchInput is! PointerUpEvent;
if ( touchresponse?.touchedSection != null) {
touchedIndex = touchresponse!.touchedSection!.touchedSectionIndex;
} else {
touchedIndex = -1;
}
});
}),
borderData: FlBorderData(
show: false,
),
sectionsSpace: 0,
centerSpaceRadius: 40,
sections: showingSections()),
),
),
),
const SizedBox(
width: 28,
),
],
),
),
);
}
List<PieChartSectionData> showingSections() {
return List.generate(2, (i) {
final isTouched = i == touchedIndex;
final fontSize = isTouched ? 25.0 : 16.0;
final radius = isTouched ? 60.0 : 50.0;
switch (i) {
case 0:
return PieChartSectionData(
color: const Color(0xff760707),
value: 40,
title: '28.3%',
radius: radius,
titleStyle: TextStyle(
fontSize: fontSize,
fontWeight: FontWeight.bold,
color: const Color(0xffffffff)),
);
case 1:
return PieChartSectionData(
color: const Color(0xff0a7005),
value: 30,
title: '16.7%',
radius: radius,
titleStyle: TextStyle(
fontSize: fontSize,
fontWeight: FontWeight.bold,
color: const Color(0xffffffff)),
);
default:
throw Error();
}
});
}
}