LinearGradient class

A 2D linear gradient.

This class is used by BoxDecoration to represent linear 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. 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 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.

This sample draws a picture that looks like vertical window shades by having a Container display a BoxDecoration with a LinearGradient.
Container(
  decoration: BoxDecoration(
    gradient: LinearGradient(
      begin: Alignment.topLeft,
      end: 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
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, override
tileMode TileMode
How this gradient should tile the plane beyond in the region before begin and after end. [...]
final
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

Methods

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

Operators

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

Static Methods

lerp(LinearGradient a, LinearGradient b, double t) LinearGradient
Linearly interpolate between two LinearGradients. [...]
override