handleKeyEvent method

  1. @override
bool handleKeyEvent(
  1. KeyEvent event
)
override

Handles user key inputs to update the internal value.

Implementation

@override
bool handleKeyEvent(term.KeyEvent event) {
  if (options.isEmpty) return false;

  if (event.type == KeyType.up) {
    _selectedIndex = (_selectedIndex - 1).clamp(0, options.length - 1);
    value = options[_selectedIndex].value;
    if (_state != null) {
      _state!.setState(() {});
    }
    return true;
  } else if (event.type == KeyType.down) {
    _selectedIndex = (_selectedIndex + 1).clamp(0, options.length - 1);
    value = options[_selectedIndex].value;
    if (_state != null) {
      _state!.setState(() {});
    }
    return true;
  }
  return false;
}