Summary
Refactor plot-point offset handling in LineChartPainter so it is safe and does not rely on global state.
Problem
LineChartPainter used a static Map<LineChartBarData, List<Offset>> _cachedOffsets to cache pixel positions for line series.
- This caused:
- Shared state across all chart instances.
- Unbounded growth: the map was never cleared, so memory could grow over time.
- Stale/cross-instance reuse: new
LineChartBarData instances (e.g. after refresh) could be confused with old keys (Equatable-based), or different charts could affect each other.
- The cache was also never populated (no write after computing), so it was dead code and still unsafe.
Solution
- Remove the static
_cachedOffsets map entirely.
- Compute plot points in
createPlotPoints(rect, lineBarData) on each paint; no global or static cache.
- Behavior is unchanged (we were already computing every time); the unsafe/dead cache is removed.
Files needs to be changed
lib/src/line_chart/line_chart_painter.dart
Checklist
Summary
Refactor plot-point offset handling in
LineChartPainterso it is safe and does not rely on global state.Problem
LineChartPainterused a staticMap<LineChartBarData, List<Offset>> _cachedOffsetsto cache pixel positions for line series.LineChartBarDatainstances (e.g. after refresh) could be confused with old keys (Equatable-based), or different charts could affect each other.Solution
_cachedOffsetsmap entirely.createPlotPoints(rect, lineBarData)on each paint; no global or static cache.Files needs to be changed
lib/src/line_chart/line_chart_painter.dartChecklist
_cachedOffsets.createPlotPointsstateless (compute and return only).createPlotPoints.