添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

This class is used by BoxDecoration to represent linear gradients. This abstracts out the arguments to the 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 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 with a gradient sweeping through different colors, by having a Container display a BoxDecoration with a LinearGradient .

To create a local project with this code sample, run:
flutter create --sample=painting.LinearGradient.1 mysample

  • RadialGradient , which displays a gradient in concentric circles, and has an example which shows a different way to use Gradient objects.
  • SweepGradient , which displays a gradient in a sweeping arc around a center point.
  • BoxDecoration , which can take a LinearGradient in its BoxDecoration.gradient property.
  • LinearGradient.new ({ AlignmentGeometry begin = Alignment.centerLeft , AlignmentGeometry end = Alignment.centerRight , required List < Color > colors , List < double > ? stops , TileMode tileMode = TileMode.clamp , GradientTransform ? transform }) Creates a linear gradient.
    const