Skip to content

Refactor: Remove global offset cache in LineChartPainter (per-instance / safe) #13

@banoth-ravinder

Description

@banoth-ravinder

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

  • Remove static _cachedOffsets.
  • Make createPlotPoints stateless (compute and return only).
  • Update doc comment for createPlotPoints.
  • No new linter issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions