doonfrs / pluto_grid_plus

PlutoGrid is a dataGrid for flutter that can be controlled by the keyboard on desktop and web. Of course, it works well on Android and IOS.
https://pluto.weblaze.dev
MIT License
27 stars 28 forks source link

[Bug] PlutoGridShortcut and arrow keys not working on linux #95

Open itsnotmeman opened 1 day ago

itsnotmeman commented 1 day ago

Steps to reproduce the bug

Just run the following code on a linux system.

Expected results

Being able to move the focused cell with the arrow keys. If I press shift, "Shift pressed" should be printed.

Actual results

Nothing happens.

Code sample

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:pluto_grid/pluto_grid.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'PlutoGrid Example',
      home: Scaffold(
        appBar: AppBar(title: const Text('PlutoGrid Example')),
        body: const SimplePlutoGrid(),
      ),
    );
  }
}

class SimplePlutoGrid extends StatelessWidget {
  const SimplePlutoGrid({super.key});

  @override
  Widget build(BuildContext context) {
    // Define the columns for the grid
    final List<PlutoColumn> columns = [
      PlutoColumn(
        title: 'ID',
        field: 'id',
        minWidth: 40,
        width: 40,
        enableContextMenu: false,
        enableDropToResize: false,
        type: PlutoColumnType.number(),
      ),
      PlutoColumn(
        title: 'Name',
        field: 'name',
        type: PlutoColumnType.text(),
      ),
      PlutoColumn(
        title: 'Age',
        field: 'age',
        type: PlutoColumnType.number(),
      ),
    ];

    // Define the rows for the grid
    final List<PlutoRow> rows = [
      PlutoRow(cells: {
        'id': PlutoCell(value: 1),
        'name': PlutoCell(value: 'Alice'),
        'age': PlutoCell(value: 25),
      }),
      PlutoRow(cells: {
        'id': PlutoCell(value: 2),
        'name': PlutoCell(value: 'Bob'),
        'age': PlutoCell(value: 30),
      }),
      PlutoRow(cells: {
        'id': PlutoCell(value: 3),
        'name': PlutoCell(value: 'Charlie'),
        'age': PlutoCell(value: 35),
      }),
    ];

    return PlutoGrid(
      columns: columns,
      rows: rows,
      onChanged: (event) {
        print('changed');
      },
      configuration: PlutoGridConfiguration(
        enableMoveHorizontalInEditing: true, // Allow horizontal navigation
        shortcut: PlutoGridShortcut(
          actions: {
            ...PlutoGridShortcut.defaultActions,
            LogicalKeySet(LogicalKeyboardKey.shift): CustomShiftKeyAction(),
          }
        )
      ),
    );
  }
}
// Override shift key action to enable to start
// typing in uppercase in a PlutoGrid cell.
class CustomShiftKeyAction extends PlutoGridShortcutAction {
  @override
  void execute({
    required PlutoKeyManagerEvent keyEvent,
    required PlutoGridStateManager stateManager,
  }) {
    stateManager.setEditing(true);
    print('Shift pressed');
  }
}

Execution Environment

Flutter version Flutter version is 3.24.5

PlutoGrid version PlutoGrid version is 8.4.1

OS Ubuntu 22.04.5