17

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.

lordarcadius
  • 181
  • 1
  • 1
  • 6

8 Answers8

14

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.

Gregory Seront
  • 746
  • 1
  • 6
  • 9
  • 2
    yes the same happend to me on flutter 2.8 with web, the bug disappear when i relaunch the app – GNassro Jan 10 '22 at 21:36
4

If you are using a StatelessWidget, convert it to a StatefulWidget and do a full restart.

In the code example from the official Flutter API documentation for TextEditingController, they are using a StatefulWidget so it's safe to assume that TextEditingControllers need to be in a StatefulWidget.

1housand
  • 508
  • 7
  • 16
  • While I agree that StatefulWidgets are just plain better because you can add/update functionality without having to refactor everything you've already done just to get to the point of having a good container, this advice goes against everything the Flutter team suggests is possible - even preferable - when using StatelessWidgets everywhere that dynamic state isn't 100% necessary. :( – ChrisH Jul 18 '22 at 14:45
  • I updated my answer with a source - the official Flutter API documentation for TextEditingController has a code example and they are using a Stateful Widget. I don't believe you can use this with a Stateless widget. Also, I think you got Stateless mixed up with Stateful in your last statement. – 1housand Jul 19 '22 at 18:14
  • I didn't confuse anything. I've used Stateless Widgets with text edit controllers pretty often. It's only been very recently I"ve started seeing this error - I think since I updated to Flutter 3 (I think, I won't swear to that). – ChrisH Jul 19 '22 at 18:37
2

When you use a physical keyboard on an emulator rapidly, this error occurred. Use 'Hot Restart' or use Emulators/Simulators keyboard while testing the app.

1

Add this two lines shrinkWrap: true and physics: ScrollPhysics(),under GridView.builder

return Scaffold(
      drawer: SideDrawer(),
        body: 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(
                  shrinkWrap: true,
                  physics: ScrollPhysics(),
                  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"]),
                      ),
                    );
                  },
                );
              }
            },
          ),
        ),
     );
Jahidul Islam
  • 11,435
  • 3
  • 17
  • 38
0

you will not find this error in release mode, this is caused by the Emulator it self. You can ignore it!

Md omer arafat
  • 398
  • 7
  • 10
0

This error also occurs when you use virtual emulators connected to your real device and you try to use physical keyboard as an input instead of Real device's keyboard

so try to input through the real device's input mode

Harsh Kothari
  • 439
  • 4
  • 8
0

I had the same problem, and even reinstalling the app didn't work.

The problem was with my simulator (iPad). So I :

  • Exited my simulator
  • Launched the simulator again
  • Reinstalled the app

And the problem disappeared.

Jack'
  • 1,722
  • 1
  • 19
  • 27
0

I had a similar issue while developing flutter for desktop apps, I was getting the error due to having capslock on, ensure it is off, for somewierd reason, on an M2 chip Macbook, and you run the app on debug mode with capslock on, you get that error. Run the app with the caps off

blackbird
  • 460
  • 3
  • 9
  • 25