SweepGradient class
A 2D sweep gradient.
This class is used by BoxDecoration to represent sweep gradients. This
abstracts out the arguments to the 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.
Container(
decoration: const BoxDecoration(
gradient: SweepGradient(
center: FractionalOffset.center,
colors: <Color>[
Color(0xFF4285F4), // blue
Color(0xFF34A853), // green
Color(0xFFFBBC05), // yellow
Color(0xFFEA4335), // red
Color(0xFF4285F4), // blue again to seamlessly transition to the start
],
stops: <double>[0.0, 0.25, 0.5, 0.75, 1.0],
),
)
)
math.pi/4
radians,
i.e. 45 degrees.
Container(
decoration: const BoxDecoration(
gradient: SweepGradient(
center: FractionalOffset.center,
colors: <Color>[
Color(0xFF4285F4), // blue
Color(0xFF34A853), // green
Color(0xFFFBBC05), // yellow
Color(0xFFEA4335), // red
Color(0xFF4285F4), // blue again to seamlessly transition to the start
],
stops: <double>[0.0, 0.25, 0.5, 0.75, 1.0],
transform: GradientRotation(math.pi/4),
),
),
)
See also:
- LinearGradient, which displays a gradient in parallel lines, and has an example which shows a different way to use Gradient objects.
- RadialGradient, which displays a gradient in concentric circles, and has an example which shows a different way to use Gradient objects.
- BoxDecoration, which can take a SweepGradient in its BoxDecoration.gradient property.
Constructors
-
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, GradientTransform? transform}) -
Creates a sweep 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.
finalinherited
- endAngle → double
-
The angle in radians at which stop 1.0 of the gradient is placed.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- startAngle → double
-
The angle in radians at which stop 0.0 of the gradient is placed.
final
-
stops
→ List<
double> ? -
A list of values from 0.0 to 1.0 that denote fractions along the gradient.
finalinherited
- tileMode → TileMode
-
How this gradient should tile the plane beyond in the region before
startAngle and after endAngle.
final
- transform → GradientTransform?
-
The transform, if any, to apply to the gradient.
finalinherited
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 -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
scale(
double factor) → SweepGradient -
Returns a new SweepGradient with its colors scaled by the given factor.
override
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Static Methods
-
lerp(
SweepGradient? a, SweepGradient? b, double t) → SweepGradient? -
Linearly interpolate between two SweepGradients.
override