RawKeyEvent.fromMessage constructor

RawKeyEvent.fromMessage(Map<String, dynamic> message)

Creates a concrete RawKeyEvent class from a message in the form received on the SystemChannels.keyEvent channel.

Implementation

factory RawKeyEvent.fromMessage(Map<String, dynamic> message) {
  RawKeyEventData data;

  final String keymap = message['keymap'];
  switch (keymap) {
    case 'android':
      data = RawKeyEventDataAndroid(
        flags: message['flags'] ?? 0,
        codePoint: message['codePoint'] ?? 0,
        keyCode: message['keyCode'] ?? 0,
        scanCode: message['scanCode'] ?? 0,
        metaState: message['metaState'] ?? 0,
      );
      break;
    case 'fuchsia':
      data = RawKeyEventDataFuchsia(
        hidUsage: message['hidUsage'] ?? 0,
        codePoint: message['codePoint'] ?? 0,
        modifiers: message['modifiers'] ?? 0,
      );
      break;
    default:
      // We don't yet implement raw key events on iOS, but we don't hit this
      // exception because the engine never sends us these messages.
      throw FlutterError('Unknown keymap for key events: $keymap');
  }

  final String type = message['type'];
  switch (type) {
    case 'keydown':
      return RawKeyDownEvent(data: data);
    case 'keyup':
      return RawKeyUpEvent(data: data);
    default:
      throw FlutterError('Unknown key event type: $type');
  }
}