A 2D linear gradient.

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

A gradient has two anchor points, begin and end. The begin point corresponds to 0.0, and the end point corresponds to 1.0. These points 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.linear, 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 before begin and after end is colored according to tileMode.

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

Sample code

This sample draws a picture that looks like vertical window shades by having a Container display a BoxDecoration with a LinearGradient.

new Container(
  decoration: new BoxDecoration(
    gradient: new LinearGradient(
      begin: Alignment.topLeft,
      end: new Alignment(0.8, 0.0), // 10% of the width, so there are ten blinds.
      colors: [const Color(0xFFFFFFEE), const Color(0xFF999999)], // whitish to gray
      tileMode: TileMode.repeated, // repeats the gradient over the canvas
    ),
  ),
)

See also:

Inheritance

Constructors

LinearGradient({AlignmentGeometry begin: Alignment.centerLeft, AlignmentGeometry end: Alignment.centerRight, @required List<Color> colors, List<double> stops, TileMode tileMode: TileMode.clamp })
Creates a linear gradient. [...]
const

Properties

begin AlignmentGeometry
The offset at which stop 0.0 of the gradient is placed. [...]
final
colors List<Color>
The colors the gradient should obtain at each of the stops. [...]
final
end AlignmentGeometry
The offset at which stop 1.0 of the gradient is placed. [...]
final
hashCode int
The hash code for this object. [...]
read-only
stops List<double>
A list of values from 0.0 to 1.0 that denote fractions of the vector from start to end. [...]
final
tileMode TileMode
How this gradient should tile the plane beyond in the region before begin and after end. [...]
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) LinearGradient
Returns a new LinearGradient with its properties (in particular the 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(LinearGradient a, LinearGradient b, double t) LinearGradient
Linearly interpolate between two LinearGradients. [...]