update method

  1. @override
void update(
  1. int dirt
)

Implementation

@override
void update(int dirt) {
  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;
  var rebuildGradient = dirt & ComponentDirt.paint != 0 ||
      localTransformed ||
      (paintsInWorldSpace && worldTransformed);
  if (rebuildGradient) {
    var colors = <ui.Color>[];
    var colorPositions = <double>[];
    for (final stop in gradientStops) {
      colors.add(stop.color);
      colorPositions.add(stop.position);
    }
    if (paintsInWorldSpace) {
      var world = shapePaintContainer.worldTransform;
      var worldStart = Vec2D.transformMat2D(Vec2D(), start, world);
      var worldEnd = Vec2D.transformMat2D(Vec2D(), end, world);
      paint.shader = makeGradient(ui.Offset(worldStart[0], worldStart[1]),
          ui.Offset(worldEnd[0], worldEnd[1]), colors, colorPositions);
    } else {
      paint.shader =
          makeGradient(startOffset, endOffset, colors, colorPositions);
    }
  }
}