update method
Updates the component state in response to a message.
Returns the updated component (often this) and an optional command.
Implementation
@override
(PasswordConfirmModel, Cmd?) update(Msg msg) {
if (msg is PasswordSubmittedMsg) {
if (!_inConfirmPhase) {
// First password entered, move to confirmation
_inConfirmPhase = true;
_error = null;
return (this, _confirmInput.init());
} else {
// Confirmation entered, check match
if (_passwordInput.value == _confirmInput.value) {
return (
this,
Cmd.message(PasswordSubmittedMsg(_passwordInput.value)),
);
} else {
_error = mismatchError;
_confirmInput.reset();
return (this, null);
}
}
}
if (msg is PasswordCancelledMsg) {
if (_inConfirmPhase) {
// Go back to first password
_inConfirmPhase = false;
_confirmInput.reset();
_error = null;
return (this, _passwordInput.focus());
} else {
return (this, Cmd.message(const PasswordCancelledMsg()));
}
}
// Delegate to appropriate input
if (_inConfirmPhase) {
final (_, cmd) = _confirmInput.update(msg);
return (this, cmd);
} else {
final (_, cmd) = _passwordInput.update(msg);
return (this, cmd);
}
}