Open javaone199 opened 7 months ago
I had the same problem and temporarily fixed it with the following code
For example we are using PieChart
to display List<Int> values
First, create another variable List<Int> valueFilterZero
with values greater than 0 only
final List<Int> value;
late final List<Int> valueFilterZero;
PieChartStatistic({super.key, required this.value}) {
valueFilterZero = value.where((item) => item > 0).toList();
}
Then when handling touchCallback
, instead of using index with value
, use it with valueFilterZero
touchCallback: (FlTouchEvent event, touchResponse) {
if (event is FlTapUpEvent && touchResponse != null) {
int indexSelectedItem =
touchResponse.touchedSection?.touchedSectionIndex ?? 0;
// doSmt(value[realIndexSelectedItem]);
doSmt(valueFilterZero[realIndexSelectedItem]);
}
}
PieChart: touched section index is incorrect if some values are zero. For example,
values: 0, 0, 100, 200, 300.
when touching the 3rd value 100, touched index is 0 that should be 2.