bosskmk / pluto_grid

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
672 stars 309 forks source link

Error: The argument type 'RawKeyEvent' can't be assigned to the parameter type 'KeyEvent'.[Bug] #1096

Closed naidu199 closed 3 weeks ago

naidu199 commented 2 months ago
https://docs.flutter.dev/platform-integration/web/initialization for more details.
../../../AppData/Local/Pub/Cache/hosted/pub.dev/pluto_grid-7.0.2/lib/src/manager/shortcut/pluto_grid_shortcut.dart:33:39: Error: The        
argument type 'RawKeyEvent' can't be assigned to the parameter type 'KeyEvent'.
 - 'RawKeyEvent' is from 'package:flutter/src/services/raw_keyboard.dart'
 ('../../../Documents/FlutterDev/flutter/packages/flutter/lib/src/services/raw_keyboard.dart').
 - 'KeyEvent' is from 'package:flutter/src/services/hardware_keyboard.dart'
 ('../../../Documents/FlutterDev/flutter/packages/flutter/lib/src/services/hardware_keyboard.dart').
      if (action.key.accepts(keyEvent.event, state)) {
                                      ^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/pluto_grid-7.0.2/lib/src/manager/shortcut/pluto_grid_shortcut.dart:33:46: Error: The        
argument type 'RawKeyboard' can't be assigned to the parameter type 'HardwareKeyboard'.
 - 'RawKeyboard' is from 'package:flutter/src/services/raw_keyboard.dart'
 ('../../../Documents/FlutterDev/flutter/packages/flutter/lib/src/services/raw_keyboard.dart').
 - 'HardwareKeyboard' is from 'package:flutter/src/services/hardware_keyboard.dart'
 ('../../../Documents/FlutterDev/flutter/packages/flutter/lib/src/services/hardware_keyboard.dart').
      if (action.key.accepts(keyEvent.event, state)) {

Getting this error while running the applictaion

Flutter version : Flutter 3.22.2 • channel stable • https://github.com/flutter/flutter.git Framework • revision 761747bfc5 (9 weeks ago) • 2024-06-05 22:15:13 +0200 Engine • revision edd8546116 Tools • Dart 3.4.3 • DevTools 2.34.3

pluto grid version : pluto_grid: ^7.0.2

naidu199 commented 2 months ago

i had solved this error created PR anyone accept it This pull request addresses an issue with key event handling in the new version of Flutter. The original code caused a type error due to changes in how key events and states are managed. The updated code snippet explicitly casts " keyEvent.event " as "KeyEvent " and "state" as "HardwareKeyboard", resolving the error.

Changes Made

File Location:

lib/src/manager/shortcut/pluto_grid_shortcut.dart (line 33)

Original Code:

if (action.key.accepts(keyEvent.event, state)) {
   action.value.execute(keyEvent: keyEvent, stateManager: stateManager);
   return true;
 }

Updated Code:

if (action.key.accepts(keyEvent.event as KeyEvent, state as HardwareKeyboard)) {
  action.value.execute(keyEvent: keyEvent, stateManager: stateManager);
  return true;
}

Reason for Changes In the new version of Flutter, there were type changes that caused the original code to throw an error. By explicitly casting the types, the code is now compatible with the updated Flutter API.

The updated code has been tested and verified to work correctly without causing the previous type error.

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 3 weeks ago

This issue was closed because it has been inactive for 14 days since being marked as stale.