update method

  1. @override
(SpinnerModel, 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
(SpinnerModel, Cmd?) update(Msg msg) {
  if (msg is! SpinnerTickMsg) {
    return (this, null);
  }

  // Only accept tick messages for this spinner
  if (msg.id > 0 && msg.id != _id) {
    return (this, null);
  }

  // Prevent duplicate ticks
  if (msg.tag > 0 && msg.tag != _tag) {
    return (this, null);
  }

  // Advance to next frame
  final nextFrame = (_frame + 1) % _spinner.frames.length;
  final nextTag = _tag + 1;
  final newSpinner = copyWith(frame: nextFrame, tag: nextTag);

  return (newSpinner, newSpinner._tickCmd());
}