Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "Assertion failed:_pressedKeys.containsKey(event.physicalKey)" error in Flutter Web

I fetched the data from an API through POST request. Then I populated the data inside a GridView Builder. But when I am scrolling the web version of the app it is giving me this error:

════════ Exception caught by services library ══════════════════════════════════
The following assertion was thrown during a platform message callback:
Assertion failed:
../…/services/hardware_keyboard.dart:441
_pressedKeys.containsKey(event.physicalKey)
"A KeyUpEvent is dispatched, but the state shows that the physical key is not pressed. If this occurs in real application, please report this bug to Flutter. If this occurs in unit tests, please ensure that simulated events follow Flutter's event model as documented in `HardwareKeyboard`. This was the event: KeyUpEvent#6f053(physicalKey: PhysicalKeyboardKey#700e3(usbHidUsage: \"0x000700e3\", debugName: \"Meta Left\"), logicalKey: LogicalKeyboardKey#4b191(keyId: \"0x200000106\", keyLabel: \"Meta Left\", debugName: \"Meta Left\"), character: null, timeStamp: 0:01:32.201000, synthesized)"


When the exception was thrown, this was the stack
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49  throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3    assertFailed
packages/flutter/src/services/hardware_keyboard.dart 441:46                   <fn>
packages/flutter/src/services/hardware_keyboard.dart 451:14                   [_assertEventIsRegular]
packages/flutter/src/services/hardware_keyboard.dart 543:5                    handleKeyEvent
packages/flutter/src/services/hardware_keyboard.dart 821:57                   handleRawKeyMessage
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54            runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5            _async
packages/flutter/src/services/hardware_keyboard.dart 808:51                   handleRawKeyMessage
packages/flutter/src/services/platform_channel.dart 73:49                     <fn>
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54            runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5            _async
packages/flutter/src/services/platform_channel.dart 72:58                     <fn>
packages/flutter/src/services/binding.dart 379:35                             <fn>
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54            runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5            _async
packages/flutter/src/services/binding.dart 376:98                             <fn>
lib/_engine/engine/platform_dispatcher.dart 1034:13                           invoke2
lib/ui/src/ui/channel_buffers.dart 25:5                                       invoke
lib/ui/src/ui/channel_buffers.dart 65:7                                       push
lib/ui/src/ui/channel_buffers.dart 130:16                                     push
lib/_engine/engine/platform_dispatcher.dart 302:25                            invokeOnPlatformMessage
lib/_engine/engine/keyboard.dart 130:39                                       [_handleHtmlEvent]
lib/_engine/engine/keyboard.dart 39:7                                         <fn>
════════════════════════════════════════════════════════════════════════════════

This is the code for populating the GridView. There isn't any error or issue with GridView. The data is being populated perfectly but as soon as I start scrolling, the above error shows in Debug console. Also, the scrolling is very laggy. It seems as if the animations are completely broken.

@override
  Widget build(BuildContext context) {
    return Container(
      child: Scaffold(
          body: Row(
        children: [
          SideDrawer(),
          Container(
            padding: EdgeInsets.all(20),
            width: MediaQuery.of(context).size.width * 0.77,
            child: FutureBuilder<dynamic>(
              future: appList(),
              builder: (context, snapshot) {
                if (snapshot.data == null) {
                  return Center(
                    child: CircularProgressIndicator(),
                  );
                } else {
                  return GridView.builder(
                    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                        crossAxisCount: 5,
                        childAspectRatio: 3 / 2,
                        crossAxisSpacing: 10,
                        mainAxisSpacing: 10),
                    itemCount: snapshot.data.length - 1,
                    itemBuilder: (context, index) {
                      return Card(
                        elevation: 2,
                        child: ListTile(
                          leading: Text(snapshot.data[index]["title"]),
                        ),
                      );
                    },
                  );
                }
              },
            ),
          ),
        ],
      )),
    );
  }

Any help will be appreciable. Thank you so much.

like image 267
lordarcadius Avatar asked Sep 09 '21 07:09

lordarcadius


1 Answers

This is an issue with hot reload: https://github.com/flutter/flutter/issues/87391. I experienced the same problem, but once I stop/relaunch the app, it disappears.

like image 175
Gregory Seront Avatar answered Sep 30 '22 05:09

Gregory Seront