handleKeyEvent method Null safety

  1. @override
void handleKeyEvent(
  1. RawKeyEvent keyEvent
)
override

Processes the selection operation when SfDataGrid receives raw keyboard event.

Implementation

@override
void handleKeyEvent(RawKeyEvent keyEvent) {
  final DataGridConfiguration dataGridConfiguration =
      _dataGridStateDetails!();
  if (dataGridConfiguration.currentCell.isEditing &&
      keyEvent.logicalKey != LogicalKeyboardKey.escape) {
    if (!dataGridConfiguration.currentCell
        .canSubmitCell(dataGridConfiguration)) {
      return;
    }

    dataGridConfiguration.currentCell
        .onCellSubmit(dataGridConfiguration, cancelCanSubmitCell: true);
  }

  if (keyEvent.logicalKey == LogicalKeyboardKey.tab) {
    _processKeyTab(keyEvent);
  }

  if (keyEvent.logicalKey == LogicalKeyboardKey.home) {
    _processHomeKey(dataGridConfiguration, keyEvent);
  }

  if (keyEvent.logicalKey == LogicalKeyboardKey.end) {
    _processEndKey(dataGridConfiguration, keyEvent);
  }

  if (keyEvent.logicalKey == LogicalKeyboardKey.pageUp) {
    _processPageUp();
  }

  if (keyEvent.logicalKey == LogicalKeyboardKey.pageDown) {
    _processPageDown();
  }

  if (keyEvent.logicalKey == LogicalKeyboardKey.arrowUp) {
    _processKeyUp(keyEvent);
  }

  if (keyEvent.logicalKey == LogicalKeyboardKey.arrowDown ||
      keyEvent.logicalKey == LogicalKeyboardKey.enter) {
    _processKeyDown(keyEvent);
    if (keyEvent.logicalKey == LogicalKeyboardKey.enter) {
      return;
    }
  }

  if (keyEvent.logicalKey == LogicalKeyboardKey.arrowLeft) {
    if (dataGridConfiguration.textDirection == TextDirection.rtl) {
      _processKeyRight(dataGridConfiguration, keyEvent);
    } else {
      _processKeyLeft(dataGridConfiguration, keyEvent);
    }
  }

  if (keyEvent.logicalKey == LogicalKeyboardKey.arrowRight) {
    if (dataGridConfiguration.textDirection == TextDirection.rtl) {
      _processKeyLeft(dataGridConfiguration, keyEvent);
    } else {
      _processKeyRight(dataGridConfiguration, keyEvent);
    }
  }

  if (keyEvent.logicalKey == LogicalKeyboardKey.keyA) {
    if (keyEvent.isControlPressed) {
      _processSelectedAll();
    }
  }

  if (keyEvent.logicalKey == LogicalKeyboardKey.space) {
    _processSpaceKey();
  }

  if (keyEvent.logicalKey == LogicalKeyboardKey.f2) {
    if (dataGridConfiguration.allowEditing &&
        dataGridConfiguration.navigationMode == GridNavigationMode.cell) {
      final RowColumnIndex rowColumnIndex = RowColumnIndex(
          dataGridConfiguration.currentCell.rowIndex,
          dataGridConfiguration.currentCell.columnIndex);
      dataGridConfiguration.currentCell.onCellBeginEdit(
          editingRowColumnIndex: rowColumnIndex,
          isProgrammatic: true,
          needToResolveIndex: false);
    }
  }

  if (keyEvent.logicalKey == LogicalKeyboardKey.escape) {
    if (dataGridConfiguration.allowEditing &&
        dataGridConfiguration.navigationMode == GridNavigationMode.cell &&
        dataGridConfiguration.currentCell.isEditing) {
      dataGridConfiguration.currentCell
          .onCellSubmit(dataGridConfiguration, isCellCancelEdit: true);
    }
  }
}