Skip to content

fix: Skip zero-value sections in PieChart touch detection - #2116

Closed
ibrahim-iqbal wants to merge 1 commit into
imaNNeo:mainfrom
ibrahim-iqbal:fix/1632-pie-touch-zero-value-sections
Closed

ibrahim-iqbal wants to merge 1 commit into
imaNNeo:mainfrom
ibrahim-iqbal:fix/1632-pie-touch-zero-value-sections

Conversation

@ibrahim-iqbal

Copy link
Copy Markdown

Summary

Fixes #1632

When PieChartSectionData entries have a value of 0, their calculated sweep angle is 0. The generateSectionPath method produces a degenerate path for zero-angle sections, and Path.contains() can return unreliable results for such paths. This causes the touched section index to be incorrect when some sections have zero values.

Example: Given values [0, 0, 100, 200, 300], touching the section for value 100 (index 2) could incorrectly return index 0.

Changes

  • pie_chart_painter.dart: Skip sections with sectionAngle == 0 in handleTouch() so only visible sections are considered touchable
  • pie_chart_painter_test.dart: Added test case with zero-value sections verifying correct touch detection

Test plan

  • All 666 existing tests pass
  • New test verifies zero-value sections are not returned as touched
  • flutter analyze reports no issues on changed files
  • dart format reports no changes needed

When sections have a value of 0, their sweep angle is 0 and the
generated path is degenerate. Path.contains() can return unreliable
results for such paths, causing the touched section index to be
incorrect.

Skip sections with a zero angle in the touch detection loop so only
visible sections are considered touchable.
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.13%. Comparing base (f3a5758) to head (dd60076).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2116   +/-   ##
=======================================
  Coverage   94.13%   94.13%           
=======================================
  Files          54       54           
  Lines        4671     4672    +1     
=======================================
+ Hits         4397     4398    +1     
  Misses        274      274           
Flag Coverage Δ
flutter 94.13% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ibrahim-iqbal

Copy link
Copy Markdown
Author

Closing as a duplicate — #2067 fixes the same issue (#1632) and is already approved pending a branch update, so no need for two open PRs on the same fix.

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

Successfully merging this pull request may close these issues.

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

1 participant