update method

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

Implementation

@override
void update(int dirt) {
  super.update(dirt);

  // When the paint gets marked dirty, we need to sync the blend mode with the
  // paints.
  if (dirt & ComponentDirt.blendMode != 0) {
    for (final fill in fills) {
      fill.blendMode = blendMode;
    }
    for (final stroke in strokes) {
      stroke.blendMode = blendMode;
    }
  }

  // RenderOpacity gets updated with the worldTransform (accumulates through
  // hierarchy), so if we see worldTransform is dirty, update our internal
  // render opacities.
  if (dirt & ComponentDirt.worldTransform != 0) {
    for (final fill in fills) {
      fill.renderOpacity = renderOpacity;
    }
    for (final stroke in strokes) {
      stroke.renderOpacity = renderOpacity;
    }
  }
  // We update before the path composer so let's get our ducks in a row, what
  // do we want? PathComposer depends on us so we're safe to update our
  // desires here.
  if (dirt & ComponentDirt.path != 0) {
    // Recompute which paths we want.
    _wantWorldPath = false;
    _wantLocalPath = false;
    for (final stroke in strokes) {
      if (stroke.transformAffectsStroke) {
        _wantLocalPath = true;
      } else {
        _wantWorldPath = true;
      }
    }

    // Update the gradients' paintsInWorldSpace properties based on whether
    // the path we'll be feeding that at draw time is in world or local space.
    // This is a good opportunity to do it as gradients depend on us so
    // they'll update after us.

    // We optmistically first fill in the space we know the stroke will be in.
    _fillInWorld = _wantWorldPath || !_wantLocalPath;

    // Gradients almost always fill in local space, unless they are bound to
    // bones.
    var mustFillLocal = fills.firstWhereOrNull(
          (fill) => fill.paintMutator is core.LinearGradient,
        ) !=
        null;
    if (mustFillLocal) {
      _fillInWorld = false;
      _wantLocalPath = true;
    }

    for (final fill in fills) {
      var mutator = fill.paintMutator;
      if (mutator is core.LinearGradient) {
        mutator.paintsInWorldSpace = _fillInWorld;
      }
    }

    for (final stroke in strokes) {
      var mutator = stroke.paintMutator;
      if (mutator is core.LinearGradient) {
        mutator.paintsInWorldSpace = !stroke.transformAffectsStroke;
      }
    }
  }
}