fix: Correct touched section index in PieChart with zero-value sections#2067
Open
mahmoodhamdi wants to merge 1 commit intoimaNNeo:mainfrom
Open
fix: Correct touched section index in PieChart with zero-value sections#2067mahmoodhamdi wants to merge 1 commit intoimaNNeo:mainfrom
mahmoodhamdi wants to merge 1 commit intoimaNNeo:mainfrom
Conversation
The handleTouch method did not skip zero-value sections, unlike drawSections which uses `continue` for sections with value == 0. This caused a path with zero sweep angle to be generated and potentially matched, returning wrong indices. Added the same skip logic to handleTouch and a unit test covering sections like [0, 0, 100, 200, 300]. Closes imaNNeo#1632
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2067 +/- ##
=======================================
Coverage 92.92% 92.92%
=======================================
Files 50 50
Lines 3873 3874 +1
=======================================
+ Hits 3599 3600 +1
Misses 274 274
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
imaNNeo
requested changes
Apr 10, 2026
| @@ -1,4 +1,5 @@ | |||
| ## newVersion | |||
| * **BUGFIX** (by @mahmoodhamdi) Fix incorrect touched section index in PieChart when some sections have zero values, #1632 | |||
Owner
There was a problem hiding this comment.
You don't need to add the changelog line in this file anymore.
We'll generate it based on the commit history from now on.
Owner
|
Good catch! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a
PieCharthas sections with zero values (e.g.,[0, 0, 100, 200, 300]), touching any visible section returns the wrongtouchedSectionIndex. For example, touching the section with value100(index 2) incorrectly returns index0.Root Cause
The
drawSectionsmethod skips zero-value sections withcontinue, so they aren't drawn. However,handleTouchdoes not skip them — it generates a section path with a zero sweep angle, which can incorrectly match a touch point before the actual visible section is checked.Solution
Added the same
if (section.value == 0) continue;check to thehandleTouchloop, matching the behavior ofdrawSections.Testing
Added a unit test with sections
[0, 0, 100, 200, 300]that verifies:Checklist
flutter analyzepasses with zero warningsflutter testpassesdart format .appliedCloses #1632