paint method Null safety

  1. @override
void paint(
  1. PaintingContext context,
  2. Offset offset
)
override

Paint this render object into the given context at the given offset.

Subclasses should override this method to provide a visual appearance for themselves. The render object's local coordinate system is axis-aligned with the coordinate system of the context's canvas and the render object's local origin (i.e, x=0 and y=0) is placed at the given offset in the context's canvas.

Do not call this function directly. If you wish to paint yourself, call markNeedsPaint instead to schedule a call to this function. If you wish to paint one of your children, call PaintingContext.paintChild on the given context.

When painting one of your children (via a paint child function on the given context), the current canvas held by the context might change because draw operations before and after painting children might need to be recorded on separate compositing layers.

Implementation

@override
void paint(PaintingContext context, Offset offset) {
  final Size? leaderSize = link.leaderSize;
  assert(
    link.leaderSize != null || (link.leader == null || leaderAnchor == Alignment.topLeft),
    '$link: layer is linked to ${link.leader} but a valid leaderSize is not set. '
    'leaderSize is required when leaderAnchor is not Alignment.topLeft '
    '(current value is $leaderAnchor).',
  );
  final Offset effectiveLinkedOffset = leaderSize == null
    ? this.offset
    : leaderAnchor.alongSize(leaderSize) - followerAnchor.alongSize(size) + this.offset;
  assert(showWhenUnlinked != null);
  if (layer == null) {
    layer = FollowerLayer(
      link: link,
      showWhenUnlinked: showWhenUnlinked,
      linkedOffset: effectiveLinkedOffset,
      unlinkedOffset: offset,
    );
  } else {
    layer
      ?..link = link
      ..showWhenUnlinked = showWhenUnlinked
      ..linkedOffset = effectiveLinkedOffset
      ..unlinkedOffset = offset;
  }
  context.pushLayer(
    layer!,
    super.paint,
    Offset.zero,
    childPaintBounds: const Rect.fromLTRB(
      // We don't know where we'll end up, so we have no idea what our cull rect should be.
      double.negativeInfinity,
      double.negativeInfinity,
      double.infinity,
      double.infinity,
    ),
  );
  assert(() {
    layer!.debugCreator = debugCreator;
    return true;
  }());
}