stopRecordingIfNeeded method

  1. @protected
  2. @mustCallSuper
void stopRecordingIfNeeded ()
@mustCallSuper, @protected

Stop recording to a canvas if recording has started.

Do not call this function directly: functions in this class will call this method as needed. This function is called internally to ensure that recording is stopped before adding layers or finalizing the results of a paint.

Subclasses that need to customize how recording to a canvas is performed should override this method to save the results of the custom canvas recordings.

Implementation

@protected
@mustCallSuper
void stopRecordingIfNeeded() {
  if (!_isRecording)
    return;
  assert(() {
    if (debugRepaintRainbowEnabled) {
      final Paint paint = Paint()
        ..style = PaintingStyle.stroke
        ..strokeWidth = 6.0
        ..color = debugCurrentRepaintColor.toColor();
      canvas.drawRect(estimatedBounds.deflate(3.0), paint);
    }
    if (debugPaintLayerBordersEnabled) {
      final Paint paint = Paint()
        ..style = PaintingStyle.stroke
        ..strokeWidth = 1.0
        ..color = const Color(0xFFFF9800);
      canvas.drawRect(estimatedBounds, paint);
    }
    return true;
  }());
  _currentLayer.picture = _recorder.endRecording();
  _currentLayer = null;
  _recorder = null;
  _canvas = null;
}