update method
Updates the component state in response to a message.
Returns the updated component (often this) and an optional command.
Implementation
@override
(DestructiveConfirmModel, Cmd?) update(Msg msg) {
if (msg is KeyMsg) {
final key = msg.key;
if (keyMatches(key, [keyMap.cancel])) {
return (this, Cmd.message(const ConfirmCancelledMsg()));
}
if (keyMatches(key, [keyMap.confirm])) {
if (isMatch) {
return (this, Cmd.message(const ConfirmResultMsg(true)));
} else if (_input.isNotEmpty) {
_error = 'Input does not match "$confirmText"';
}
return (this, null);
}
// Handle backspace
if (key.type == KeyType.backspace) {
if (_input.isNotEmpty) {
_input.removeLast();
_error = null;
}
return (this, null);
}
// Handle character input
if (key.runes.isNotEmpty) {
final text = String.fromCharCodes(key.runes);
for (final g in uni.graphemes(text)) {
final cp = uni.firstCodePoint(g);
if (cp >= 32 && cp != 127) {
_input.add(g);
_error = null;
}
}
return (this, null);
}
}
return (this, null);
}