Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PieChart: touched section index is incorrect if some values are zero #1632

Open
javaone199 opened this issue Apr 11, 2024 · 1 comment
Open

Comments

@javaone199
Copy link

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.

@javaone199 javaone199 changed the title PieChart: touched section index is correct if some values are zero PieChart: touched section index is incorrect if some values are zero Apr 11, 2024
@tungthanh1497
Copy link

tungthanh1497 commented May 3, 2024

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]);
     }
   }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants