onKey method

  1. @override
bool onKey(
  1. KeyEvent event,
  2. RenderContext ctx
)
override

Implementation

@override
bool onKey(KeyEvent event, RenderContext ctx) {
  final big = pageStep ?? ((max - min) / 10);
  switch (event.key) {
    case NamedKey.arrowLeft:
    case NamedKey.arrowDown:
      _adjust(-step);
      return true;
    case NamedKey.arrowRight:
    case NamedKey.arrowUp:
      _adjust(step);
      return true;
    case NamedKey.pageDown:
      _adjust(-big);
      return true;
    case NamedKey.pageUp:
      _adjust(big);
      return true;
    case NamedKey.home:
      if (state.active == RangeHandle.low) {
        if (state.low == min) return true;
        state.low = min;
      } else {
        if (state.high == state.low) return true;
        state.high = state.low;
      }
      onChanged?.call(state.low, state.high);
      return true;
    case NamedKey.end:
      if (state.active == RangeHandle.high) {
        if (state.high == max) return true;
        state.high = max;
      } else {
        if (state.low == state.high) return true;
        state.low = state.high;
      }
      onChanged?.call(state.low, state.high);
      return true;
    case NamedKey.tab:
      _toggleActive();
      return true;
    default:
      if (event.char == ' ') {
        _toggleActive();
        return true;
      }
      return false;
  }
}