forked from imaNNeo/fl_chart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpie_chart_sample1.dart
More file actions
146 lines (141 loc) · 4.83 KB
/
pie_chart_sample1.dart
File metadata and controls
146 lines (141 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'indicator.dart';
class PieChartSample1 extends StatefulWidget {
@override
State<StatefulWidget> createState() => PieChartSample1State();
}
class PieChartSample1State extends State {
int touchedIndex;
@override
Widget build(BuildContext context) {
return AspectRatio(
aspectRatio: 1.3,
child: Card(
color: Colors.white,
child: Column(
children: <Widget>[
const SizedBox(
height: 28,
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Indicator(
color: const Color(0xff0293ee),
text: 'One',
isSquare: false,
size: touchedIndex == 0 ? 18 : 16,
textColor: touchedIndex == 0 ? Colors.black : Colors.grey,
),
Indicator(
color: const Color(0xfff8b250),
text: 'Two',
isSquare: false,
size: touchedIndex == 1 ? 18 : 16,
textColor: touchedIndex == 1 ? Colors.black : Colors.grey,
),
Indicator(
color: const Color(0xff845bef),
text: 'Three',
isSquare: false,
size: touchedIndex == 2 ? 18 : 16,
textColor: touchedIndex == 2 ? Colors.black : Colors.grey,
),
Indicator(
color: const Color(0xff13d38e),
text: 'Four',
isSquare: false,
size: touchedIndex == 3 ? 18 : 16,
textColor: touchedIndex == 3 ? Colors.black : Colors.grey,
),
],
),
const SizedBox(
height: 18,
),
Expanded(
child: AspectRatio(
aspectRatio: 1,
child: PieChart(
PieChartData(
pieTouchData: PieTouchData(touchCallback: (pieTouchResponse) {
setState(() {
if (pieTouchResponse.touchInput is FlLongPressEnd ||
pieTouchResponse.touchInput is FlPanEnd) {
touchedIndex = -1;
} else {
touchedIndex = pieTouchResponse.touchedSectionIndex;
}
});
}),
startDegreeOffset: 180,
borderData: FlBorderData(
show: false,
),
sectionsSpace: 12,
centerSpaceRadius: 0,
sections: showingSections()),
),
),
),
],
),
),
);
}
List<PieChartSectionData> showingSections() {
return List.generate(
4,
(i) {
final isTouched = i == touchedIndex;
final double opacity = isTouched ? 1 : 0.6;
switch (i) {
case 0:
return PieChartSectionData(
color: const Color(0xff0293ee).withOpacity(opacity),
value: 25,
title: '',
radius: 80,
titleStyle: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold, color: const Color(0xff044d7c)),
titlePositionPercentageOffset: 0.55,
);
case 1:
return PieChartSectionData(
color: const Color(0xfff8b250).withOpacity(opacity),
value: 25,
title: '',
radius: 65,
titleStyle: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold, color: const Color(0xff90672d)),
titlePositionPercentageOffset: 0.55,
);
case 2:
return PieChartSectionData(
color: const Color(0xff845bef).withOpacity(opacity),
value: 25,
title: '',
radius: 60,
titleStyle: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold, color: const Color(0xff4c3788)),
titlePositionPercentageOffset: 0.6,
);
case 3:
return PieChartSectionData(
color: const Color(0xff13d38e).withOpacity(opacity),
value: 25,
title: '',
radius: 70,
titleStyle: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold, color: const Color(0xff0c7f55)),
titlePositionPercentageOffset: 0.55,
);
default:
return null;
}
},
);
}
}