draw method Null safety

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

Draw the contents of this drawable component in world transform space.

Implementation

@override
void draw(ui.Canvas canvas) {
  bool clipped = clip(canvas);
  var path = pathComposer.fillPath;
  if (!_fillInWorld) {
    canvas.save();
    canvas.transform(worldTransform.mat4);
  }
  for (final fill in fills) {
    fill.draw(canvas, path);
  }
  if (!_fillInWorld) {
    canvas.restore();
  }

  // Strokes are slightly more complicated, they may want a local path. Note
  // that we've already built this up during our update and processed any
  // gradients to have their offsets in the correct transform space (see our
  // update method).
  for (final stroke in strokes) {
    // stroke.draw(canvas, _pathComposer);
    var transformAffectsStroke = stroke.transformAffectsStroke;
    var path = transformAffectsStroke
        ? pathComposer.localPath
        : pathComposer.worldPath;

    if (transformAffectsStroke) {
      // Get into world space.
      canvas.save();
      canvas.transform(worldTransform.mat4);
      stroke.draw(canvas, path);
      canvas.restore();
    } else {
      stroke.draw(canvas, path);
    }
  }

  if (clipped) {
    canvas.restore();
  }
}