update method Null safety

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

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);
    }
    // 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 = 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);
    }
  }
}