apply method

  1. @override
void apply(
  1. double progress
)
override

Apply the given progress level to the effect's target.

Here progress is a variable that is typically in the range from 0 to 1, with 0 being the initial state, and 1 the final state of the effect. See EffectController for details.

This is a main method that MUST be implemented in every derived class.

Implementation

@override
void apply(double progress) {
  final deltaProgress = progress - previousProgress;
  final currentAlpha = target.getAlpha(paintId: paintId);
  final deltaAlpha =
      (_alphaOffset * deltaProgress) + _roundingError * deltaProgress.sign;
  final remainder = deltaAlpha.remainder(1.0).abs();
  _roundingError = remainder >= 0.5 ? -1 * (1.0 - remainder) : remainder;
  var nextAlpha = (currentAlpha + deltaAlpha).round();
  if (nextAlpha < 0) {
    _roundingError += nextAlpha.abs();
  } else if (nextAlpha > 255) {
    _roundingError += nextAlpha - 255;
  }
  nextAlpha = nextAlpha.clamp(0, 255);
  target.setAlpha(nextAlpha, paintId: paintId);
}