onPaint method Null safety

  1. @override
void onPaint(
  1. Canvas canvas
)
override

Draws segment in series bounds.

Implementation

@override
void onPaint(Canvas canvas) {
  final Rect _rect = _calculatePlotOffset(
      _seriesRenderer._chartState!._chartAxis._axisClipRect,
      Offset(_seriesRenderer._xAxisRenderer!._axis.plotOffset,
          _seriesRenderer._yAxisRenderer!._axis.plotOffset));
  _path = Path();
  if (_series.animationDuration > 0 &&
      !_seriesRenderer._reAnimate &&
      _seriesRenderer._chartState!._widgetNeedUpdate &&
      !_seriesRenderer._chartState!._isLegendToggled &&
      _seriesRenderer._chartState!._oldSeriesRenderers.isNotEmpty &&
      _oldSeriesRenderer != null &&
      _oldSeriesRenderer!._segments.isNotEmpty &&
      _oldSeriesRenderer!._segments[0] is StepLineSegment &&
      _seriesRenderer._chartState!._oldSeriesRenderers.length - 1 >=
          _seriesRenderer._segments[currentSegmentIndex!]._seriesIndex &&
      _seriesRenderer._segments[currentSegmentIndex!]._oldSeriesRenderer!
          ._segments.isNotEmpty) {
    _currentSegment =
        _seriesRenderer._segments[currentSegmentIndex!] as StepLineSegment;
    _oldSegment = (_currentSegment._oldSeriesRenderer!._segments.length - 1 >=
            currentSegmentIndex!)
        ? _currentSegment._oldSeriesRenderer!._segments[currentSegmentIndex!]
            as StepLineSegment?
        : null;
    _oldX1 = _oldSegment?._x1;
    _oldY1 = _oldSegment?._y1;
    _oldX2 = _oldSegment?._x2;
    _oldY2 = _oldSegment?._y2;
    _oldX3 = _oldSegment?._x3;
    _oldY3 = _oldSegment?._y3;

    if (_oldSegment != null &&
        (_oldX1!.isNaN || _oldX2!.isNaN) &&
        _seriesRenderer._chartState!._oldAxisRenderers.isNotEmpty) {
      _oldXAxisRenderer = _getOldAxisRenderer(_seriesRenderer._xAxisRenderer!,
          _seriesRenderer._chartState!._oldAxisRenderers);
      _oldYAxisRenderer = _getOldAxisRenderer(_seriesRenderer._yAxisRenderer!,
          _seriesRenderer._chartState!._oldAxisRenderers);
      if (_oldYAxisRenderer != null && _oldXAxisRenderer != null) {
        _needAnimate = _oldYAxisRenderer!._visibleRange!.minimum !=
                _seriesRenderer._yAxisRenderer!._visibleRange!.minimum ||
            _oldYAxisRenderer!._visibleRange!.maximum !=
                _seriesRenderer._yAxisRenderer!._visibleRange!.maximum ||
            _oldXAxisRenderer!._visibleRange!.minimum !=
                _seriesRenderer._xAxisRenderer!._visibleRange!.minimum ||
            _oldXAxisRenderer!._visibleRange!.maximum !=
                _seriesRenderer._xAxisRenderer!._visibleRange!.maximum;
      }
      if (_needAnimate) {
        _oldLocation = _calculatePoint(
            _x1Pos,
            _y1Pos,
            _oldXAxisRenderer!,
            _oldYAxisRenderer!,
            _seriesRenderer._chartState!._requireInvertedAxis,
            _series,
            _rect);
        _oldX1 = _oldLocation!.x;
        _oldY1 = _oldLocation!.y;

        _oldLocation = _calculatePoint(
            _x2Pos,
            _y2Pos,
            _oldXAxisRenderer!,
            _oldYAxisRenderer!,
            _seriesRenderer._chartState!._requireInvertedAxis,
            _series,
            _rect);
        _oldX2 = _oldLocation!.x;
        _oldY2 = _oldLocation!.y;
        _oldLocation = _calculatePoint(
            _midX,
            _midY,
            _oldXAxisRenderer!,
            _oldYAxisRenderer!,
            _seriesRenderer._chartState!._requireInvertedAxis,
            _series,
            _rect);
        _oldX3 = _oldLocation!.x;
        _oldY3 = _oldLocation!.y;
      }
    }
    _animateLineTypeSeries(
      canvas,
      _seriesRenderer,
      strokePaint!,
      animationFactor,
      _currentSegment._x1,
      _currentSegment._y1,
      _currentSegment._x2,
      _currentSegment._y2,
      _oldX1,
      _oldY1,
      _oldX2,
      _oldY2,
      _currentSegment._x3,
      _currentSegment._y3,
      _oldX3,
      _oldY3,
    );
  } else {
    if (_series.dashArray[0] != 0 && _series.dashArray[1] != 0) {
      _path.moveTo(_x1, _y1);
      _path.lineTo(_x3, _y3);
      _path.lineTo(_x2, _y2);
      _drawDashedLine(canvas, _series.dashArray, strokePaint!, _path);
    } else {
      canvas.drawLine(Offset(_x1, _y1), Offset(_x3, _y3), strokePaint!);
      canvas.drawLine(Offset(_x3, _y3), Offset(_x2, _y2), strokePaint!);
    }
  }
}