A 2D radial gradient.

This class is used by BoxDecoration to represent gradients. This abstracts out the arguments to the new ui.Gradient.radial constructor from the dart:ui library.

A gradient has a center and a radius. The center point corresponds to 0.0, and the ring at radius from the center corresponds to 1.0. These lengths are expressed in fractions, so that the same gradient can be reused with varying sized boxes without changing the parameters. (This contrasts with new ui.Gradient.radial, whose arguments are expressed in logical pixels.)

The colors are described by a list of Color objects. There must be at least two colors. If there are more than two, a stops list must be provided. It must have the same length as colors, and specifies the position of each color stop between 0.0 and 1.0.

The region of the canvas beyond radius from the center is colored according to tileMode.

Typically this class is used with BoxDecoration, which does the painting. To use a RadialGradient to paint on a canvas directly, see createShader.

Sample code

This function draws a gradient that looks like a sun in a blue sky.

void paintSky(Canvas canvas, Rect rect) {
  var gradient = new RadialGradient(
    center: const Alignment(0.7, -0.6), // near the top right
    radius: 0.2,
    colors: [
      const Color(0xFFFFFF00), // yellow sun
      const Color(0xFF0099FF), // blue sky
    ],
    stops: [0.4, 1.0],
  );
  // rect is the area we are painting over
  var paint = new Paint()
    ..shader = gradient.createShader(rect);
  canvas.drawRect(rect, paint);
}

See also:

Inheritance

Constructors

RadialGradient({AlignmentGeometry center: Alignment.center, double radius: 0.5, @required List<Color> colors, List<double> stops, TileMode tileMode: TileMode.clamp })
Creates a radial gradient. [...]
const

Properties

center AlignmentGeometry
The center of the gradient, as an offset into the (-1.0, -1.0) x (1.0, 1.0) square describing the gradient which will be mapped onto the paint box. [...]
final
colors List<Color>
The colors the gradient should obtain at each of the stops. [...]
final
hashCode int
The hash code for this object. [...]
read-only
radius double
The radius of the gradient, as a fraction of the shortest side of the paint box. [...]
final
stops List<double>
A list of values from 0.0 to 1.0 that denote concentric rings. [...]
final
tileMode TileMode
How this gradient should tile the plane beyond the outer ring at radius pixels from the center. [...]
final
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

createShader(Rect rect, { TextDirection textDirection }) Shader
Creates a Shader for this gradient to fill the given rect. [...]
lerpFrom(Gradient a, double t) Gradient
Linearly interpolates from a to this. [...]
lerpTo(Gradient b, double t) Gradient
Linearly interpolates from this to b. [...]
scale(double factor) RadialGradient
Returns a new RadialGradient with its colors scaled by the given factor. [...]
toString() String
Returns a string representation of this object.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited

Operators

operator ==(other) bool
The equality operator. [...]

Static Methods

lerp(RadialGradient a, RadialGradient b, double t) RadialGradient
Linearly interpolate between two RadialGradients. [...]