update method
Updates the component state in response to a message.
Returns the updated component (often this) and an optional command.
Implementation
@override
(CursorModel, Cmd?) update(Msg msg) {
switch (msg) {
case _InitialBlinkMsg():
if (_mode != CursorMode.blink || !_focus) {
return (this, null);
}
return (this, _blinkCmd());
case FocusMsg(focused: true):
return focus();
case FocusMsg(focused: false):
return (blur(), null);
case CursorBlinkMsg(:final id, :final tag):
// Only accept blink messages for this cursor
if (_mode != CursorMode.blink || !_focus) {
return (this, null);
}
if (id != _id || tag != _blinkTag) {
return (this, null);
}
// Toggle blink state
final newCursor = copyWith(blink: !_blink, blinkTag: _blinkTag + 1);
return (newCursor, newCursor._blinkCmd());
case _BlinkCanceledMsg():
return (this, null);
default:
return (this, null);
}
}