handleKeyData method Null safety

bool handleKeyData(
  1. KeyData data
)

Dispatch a key data to global and leaf listeners.

This method is the handler to the global onKeyData API.

Implementation

bool handleKeyData(ui.KeyData data) {
  _transitMode ??= KeyDataTransitMode.keyDataThenRawKeyData;
  switch (_transitMode!) {
    case KeyDataTransitMode.rawKeyData:
      assert(false, 'Should never encounter KeyData when transitMode is rawKeyData.');
      return false;
    case KeyDataTransitMode.keyDataThenRawKeyData:
      assert((data.physical == 0 && data.logical == 0) ||
             (data.physical != 0 && data.logical != 0));
      // Postpone key event dispatching until the handleRawKeyMessage.
      //
      // Having 0 as the physical or logical ID indicates an empty key data,
      // transmitted to ensure that the transit mode is correctly inferred.
      if (data.physical != 0 && data.logical != 0) {
        _keyEventsSinceLastMessage.add(_eventFromData(data));
      }
      return false;
  }
}