paint method

  1. @override
FlagParentBounds? paint(
  1. Canvas canvas,
  2. Size size
)
override

Paints the flag elements on the given canvas and size.

This method iterates over the properties and uses the appropriate painter for each shape. If the properties are of type CustomElementsProperties, it calls paintFlagElements to perform additional painting.

  • canvas: The canvas on which to paint.
  • size: The size of the area to paint.

Returns a FlagParentBounds object representing the bounds of the painted elements.

Implementation

@override
FlagParentBounds? paint(Canvas canvas, Size size) {
  // No clip here: the caller has already clipped to `size`.
  bool hasPaintedElements = false;
  for (final props in properties) {
    final shape = props.shape;
    if (shape != null) {
      painter(shape)([props], size.aspectRatio).paint(canvas, size);
    }

    // [paintFlagElements] paints every custom element of this flag in one
    // go, so calling it again would only redraw the same emblem on itself.
    if (hasPaintedElements || props is! CustomElementsProperties) continue;
    hasPaintedElements = true;
    paintFlagElements(canvas, size);
  }

  return null;
}