fromColor method

Gradient fromColor(
  1. Color color
)

Returns a copy of this gradient with all of its colors replaced by the given color.

The geometry of the gradient (such as its stops and the subclass-specific positioning) is preserved, so the result paints as a uniform color. This is useful to represent a solid color as a gradient, for example when interpolating between a color and a gradient with lerp.

Subclasses should override this method to preserve their own geometry. The base implementation returns a LinearGradient; this is sufficient because a gradient with uniform colors paints as a solid color regardless of its geometry.

Implementation

Gradient fromColor(Color color) {
  return LinearGradient(
    colors: List<Color>.filled(colors.length, color),
    stops: stops,
    transform: transform,
  );
}