applyRepeatingRadial method

Gradient applyRepeatingRadial({
  1. required List<Color> colors,
  2. Shape? shape,
  3. RadialGradientPosition? position,
  4. List<Dim>? stops,
})

Adds a repeating radial gradient.

Example

final ripple = Gradient()
  ..applyRepeatingRadial(
    colors: const [Color('#ff0000'), Color('#0000ff')],
    shape: Shape.circle,
    position: RadialGradientPosition.center,
    stops: const [Dim.px(0), Dim.px(15)],
  );
  • colors: List of stop colors.
  • shape: Shape of the gradient (e.g., Shape.circle, Shape.ellipse).
  • position: Position of the gradient center (e.g., RadialGradientPosition.center).
  • stops: Optional stops corresponding to colors. Accepts length or percentage units (e.g., Dim.percent(50), Dim.px(20), Dim.rem(1.5)). Unitless numbers are not valid CSS.

Implementation

Gradient applyRepeatingRadial({
  required List<Color> colors,
  Shape? shape,
  RadialGradientPosition? position,
  List<Dim>? stops,
}) {
  final List<String> parts = [];

  if (shape != null && position != null) {
    parts.add('${shape.value} at ${position.value}');
  } else if (shape != null) {
    parts.add(shape.value);
  } else if (position != null) {
    parts.add('at ${position.value}');
  }

  for (int i = 0; i < colors.length; i++) {
    final colorStr = colors[i].value;

    if (stops != null && i < stops.length) {
      parts.add('$colorStr ${stops[i]}');
    } else {
      parts.add(colorStr);
    }
  }

  _gradients.add(GradientType.repeatingRadial.cssText(parts));

  return this;
}