lor*_*ius 21 dart flutter flutter-web
我通过 POST 请求从 API 获取数据。然后我将数据填充到 GridView Builder 中。但是当我滚动应用程序的网络版本时,它给了我这个错误:
\n\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90 Exception caught by services library \xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nThe following assertion was thrown during a platform message callback:\nAssertion failed:\n../\xe2\x80\xa6/services/hardware_keyboard.dart:441\n_pressedKeys.containsKey(event.physicalKey)\n"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)"\n\n\nWhen the exception was thrown, this was the stack\ndart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49 throw_\ndart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3 assertFailed\npackages/flutter/src/services/hardware_keyboard.dart 441:46 <fn>\npackages/flutter/src/services/hardware_keyboard.dart 451:14 [_assertEventIsRegular]\npackages/flutter/src/services/hardware_keyboard.dart 543:5 handleKeyEvent\npackages/flutter/src/services/hardware_keyboard.dart 821:57 handleRawKeyMessage\ndart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody\ndart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async\npackages/flutter/src/services/hardware_keyboard.dart 808:51 handleRawKeyMessage\npackages/flutter/src/services/platform_channel.dart 73:49 <fn>\ndart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody\ndart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async\npackages/flutter/src/services/platform_channel.dart 72:58 <fn>\npackages/flutter/src/services/binding.dart 379:35 <fn>\ndart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody\ndart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async\npackages/flutter/src/services/binding.dart 376:98 <fn>\nlib/_engine/engine/platform_dispatcher.dart 1034:13 invoke2\nlib/ui/src/ui/channel_buffers.dart 25:5 invoke\nlib/ui/src/ui/channel_buffers.dart 65:7 push\nlib/ui/src/ui/channel_buffers.dart 130:16 push\nlib/_engine/engine/platform_dispatcher.dart 302:25 invokeOnPlatformMessage\nlib/_engine/engine/keyboard.dart 130:39 [_handleHtmlEvent]\nlib/_engine/engine/keyboard.dart 39:7 <fn>\n\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nRun Code Online (Sandbox Code Playgroud)\n这是填充 GridView 的代码。GridView 没有任何错误或问题。数据正在完美填充,但一旦我开始滚动,上述错误就会显示在调试控制台中。此外,滚动非常滞后。看起来好像动画完全被破坏了。
\n@override\n Widget build(BuildContext context) {\n return Container(\n child: Scaffold(\n body: Row(\n children: [\n SideDrawer(),\n Container(\n padding: EdgeInsets.all(20),\n width: MediaQuery.of(context).size.width * 0.77,\n child: FutureBuilder<dynamic>(\n future: appList(),\n builder: (context, snapshot) {\n if (snapshot.data == null) {\n return Center(\n child: CircularProgressIndicator(),\n );\n } else {\n return GridView.builder(\n gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(\n crossAxisCount: 5,\n childAspectRatio: 3 / 2,\n crossAxisSpacing: 10,\n mainAxisSpacing: 10),\n itemCount: snapshot.data.length - 1,\n itemBuilder: (context, index) {\n return Card(\n elevation: 2,\n child: ListTile(\n leading: Text(snapshot.data[index]["title"]),\n ),\n );\n },\n );\n }\n },\n ),\n ),\n ],\n )),\n );\n }\nRun Code Online (Sandbox Code Playgroud)\n任何帮助都将非常重要。太感谢了。
\n如果您使用的是 a StatelessWidget,请将其转换为 aStatefulWidget并完全重新启动。
在官方 Flutter API文档的代码示例中,TextEditingController他们使用的是 a StatefulWidget,因此可以安全地假设TextEditingControllers 需要位于 a 中StatefulWidget。
添加这两行shrinkWrap: true
并physics: ScrollPhysics(),在下面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"]),
),
);
},
);
}
},
),
),
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17420 次 |
| 最近记录: |