update method
Implementation
@override
void update(int dirt) {
// Do the stops need to be re-ordered?
bool stopsChanged = dirt & ComponentDirt.stops != 0;
if (stopsChanged) {
gradientStops.sort((a, b) => a.position.compareTo(b.position));
}
bool worldTransformed = dirt & ComponentDirt.worldTransform != 0;
bool localTransformed = dirt & ComponentDirt.transform != 0;
// We rebuild the gradient if the gradient is dirty or we paint in world
// space and the world space transform has changed, or the local transform
// has changed. Local transform changes when a stop moves in local space.
var rebuildGradient = dirt & ComponentDirt.paint != 0 ||
localTransformed ||
(paintsInWorldSpace && worldTransformed);
if (rebuildGradient) {
// build up the color and positions lists
var colors = <ui.Color>[];
var colorPositions = <double>[];
for (final stop in gradientStops) {
colors.add(stop.color);
colorPositions.add(stop.position.clamp(0.0, 1.0));
}
// Check if we need to update the world space gradient.
if (paintsInWorldSpace) {
// Get the start and end of the gradient in world coordinates (world
// transform of the shape).
var world = shapePaintContainer!.worldTransform;
var worldStart = world * start;
var worldEnd = world * end;
paint.shader = makeGradient(ui.Offset(worldStart.x, worldStart.y),
ui.Offset(worldEnd.x, worldEnd.y), colors, colorPositions);
} else {
paint.shader =
makeGradient(startOffset, endOffset, colors, colorPositions);
}
}
}