update method

  1. @override
(ProgressModel, Cmd?) update(
  1. Msg msg
)
override

Updates the component state in response to a message.

Returns the updated component (often this) and an optional command.

Implementation

@override
(ProgressModel, Cmd?) update(Msg msg) {
  if (msg is! ProgressFrameMsg) {
    return (this, null);
  }

  if (msg.id != _id || msg.tag != _tag) {
    return (this, null);
  }

  // Stop animating if we've reached equilibrium
  if (!isAnimating) {
    return (this, null);
  }

  if (indeterminate) {
    // Update pulse offset
    final nextOffset = (_pulseOffset + 0.02) % 1.0;
    final newModel = copyWith(pulseOffset: nextOffset, tag: _tag);
    return (newModel, newModel._nextFrame());
  }

  // Update spring animation
  final (newPercent, newVelocity) = _spring.update(
    _percentShown,
    _velocity,
    _targetPercent,
  );

  final newModel = copyWith(percentShown: newPercent, velocity: newVelocity);

  return (newModel, newModel._nextFrame());
}