SweepGradient class

A 2D sweep gradient.

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

A gradient has a center, a startAngle, and an endAngle. The startAngle corresponds to 0.0, and the endAngle corresponds to 1.0. These angles are expressed in radians.

The colors are described by a list of Color objects. There must be at least two colors. The stops list, if specified, must have the same length as colors. It specifies fractions of the vector from start to end, between 0.0 and 1.0, for each color. If it is null, a uniform distribution is assumed.

The region of the canvas before startAngle and after endAngle is colored according to tileMode.

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

This sample draws a different color in each quadrant.
  decoration: BoxDecoration(
    gradient: SweepGradient(
      center: FractionalOffset.center,
      startAngle: 0.0,
      endAngle: math.pi * 2,
      colors: const <Color>[
        Color(0xFF4285F4), // blue
        Color(0xFF34A853), // green
        Color(0xFFFBBC05), // yellow
        Color(0xFFEA4335), // red
        Color(0xFF4285F4), // blue again to seamlessly transition to the start
      stops: const <double>[0.0, 0.25, 0.5, 0.75, 1.0],

See also:



SweepGradient({AlignmentGeometry center: Alignment.center, double startAngle: 0.0, double endAngle: math.pi * 2, @required List<Color> colors, List<double> stops, TileMode tileMode: TileMode.clamp })
Creates a sweep gradient. [...]


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. [...]
endAngle double
The angle in radians at which stop 1.0 of the gradient is placed. [...]
hashCode int
The hash code for this object. [...]
read-only, override
startAngle double
The angle in radians at which stop 0.0 of the gradient is placed. [...]
tileMode TileMode
How this gradient should tile the plane beyond in the region before startAngle and after endAngle. [...]
colors List<Color>
The colors the gradient should obtain at each of the stops. [...]
final, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
stops List<double>
A list of values from 0.0 to 1.0 that denote fractions along the gradient. [...]
final, inherited


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 another Gradient to this. [...]
lerpTo(Gradient b, double t) Gradient
Linearly interpolates from this to another Gradient. [...]
scale(double factor) SweepGradient
Returns a new SweepGradient 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. [...]


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

Static Methods

lerp(SweepGradient a, SweepGradient b, double t) SweepGradient
Linearly interpolate between two SweepGradients. [...]