handleKeyEvent method
Handles user key inputs to update the internal value.
Implementation
@override
void handleKeyEvent(KeyEvent event) {
if (options.isEmpty) return;
final currentVal = value ?? [];
for (var i = 0; i < options.length; i++) {
_selected[i] = currentVal.contains(options[i].value);
}
if (event.type == KeyType.up) {
_selectedIndex = (_selectedIndex - 1).clamp(0, options.length - 1);
if (_state != null) {
_state!.setState(() {});
}
} else if (event.type == KeyType.down) {
_selectedIndex = (_selectedIndex + 1).clamp(0, options.length - 1);
if (_state != null) {
_state!.setState(() {});
}
} else if (event.key == ' ' || event.type == KeyType.enter) {
_selected[_selectedIndex] = !_selected[_selectedIndex];
final nextVal = <T>[];
for (var i = 0; i < options.length; i++) {
if (_selected[i]) {
nextVal.add(options[i].value);
}
}
value = nextVal;
if (_state != null) {
_state!.setState(() {});
}
}
}