flutter报错Cannot hit test a render box that has never been laid out

2024-01-16 18:20

本文主要是介绍flutter报错Cannot hit test a render box that has never been laid out,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

出现这个问题的原因可能是因为你把一个ListView或者GridView放到了一个没有设置大小的容器里面导致的,所以意思是不能渲染那一个没有布局过的容器。我这里遇到的错误是因为我把GridView放到了一个Container里面,并且我没有设置Container宽高。

就导致了那个错误:

======== Exception caught by gestures library ======================================================
The following assertion was thrown while handling a pointer data packet:
Cannot hit test a render box that has never been laid out.

The hitTest() method was called on this RenderBox: RenderStack#349bb NEEDS-LAYOUT NEEDS-PAINT
...  parentData: offset=Offset(0.0, 0.0); id=_ScaffoldSlot.floatingActionButton
...  constraints: MISSING
...  size: MISSING
...  alignment: Alignment.centerRight
...  textDirection: ltr
...  fit: loose
Unfortunately, this object's geometry is not known at this time, probably because it has never been laid out. This means it cannot be accurately hit-tested.

If you are trying to perform a hit test during the layout phase itself, make sure you only hit test nodes that have completed layout (e.g. the node's children, after their layout() method has been called).

When the exception was thrown, this was the stack: 
#0      RenderBox.hitTest.<anonymous closure> (package:flutter/src/rendering/box.dart:2442:11)
#1      RenderBox.hitTest (package:flutter/src/rendering/box.dart:2473:6)
#2      RenderBoxContainerDefaultsMixin.defaultHitTestChildren.<anonymous closure> (package:flutter/src/rendering/box.dart:2854:25)
#3      BoxHitTestResult.addWithPaintOffset (package:flutter/src/rendering/box.dart:800:31)
#4      RenderBoxContainerDefaultsMixin.defaultHitTestChildren (package:flutter/src/rendering/box.dart:2849:33)
#5      RenderCustomMultiChildLayoutBox.hitTestChildren (package:flutter/src/rendering/custom_layout.dart:415:12)
#6      RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#7      RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#8      RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#9      RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#10     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#11     RenderPhysicalModel.hitTest (package:flutter/src/rendering/proxy_box.dart:1990:18)
#12     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#13     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#14     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#15     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#16     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#17     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#18     RenderIgnorePointer.hitTest (package:flutter/src/rendering/proxy_box.dart:3609:31)
#19     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#20     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#21     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#22     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#23     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#24     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#25     RenderOffstage.hitTest (package:flutter/src/rendering/proxy_box.dart:3738:31)
#26     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#27     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#28     _RenderTheaterMixin.hitTestChildren.childHitTest (package:flutter/src/widgets/overlay.dart:856:81)
#29     BoxHitTestResult.addWithPaintOffset (package:flutter/src/rendering/box.dart:800:31)
#30     _RenderTheaterMixin.hitTestChildren (package:flutter/src/widgets/overlay.dart:857:22)
#31     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#32     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#33     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#34     RenderAbsorbPointer.hitTest (package:flutter/src/rendering/proxy_box.dart:3856:17)
#35     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#36     RenderProxyBoxWithHitTestBehavior.hitTest (package:flutter/src/rendering/proxy_box.dart:172:19)
#37     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#38     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#39     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#40     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#41     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#42     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#43     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#44     RenderTapRegionSurface.hitTest (package:flutter/src/widgets/tap_region.dart:213:28)
#45     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#46     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#47     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#48     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#49     RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
#50     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2475:11)
#51     RenderView.hitTest (package:flutter/src/rendering/view.dart:194:14)
#52     RendererBinding.hitTestInView (package:flutter/src/rendering/binding.dart:534:16)
#53     GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:384:7)
#54     GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:376:5)
#55     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:323:7)
#56     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:292:9)
#57     _invoke1 (dart:ui/hooks.dart:186:13)
#58     PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:424:7)
#59     _dispatchPointerDataPacket (dart:ui/hooks.dart:119:31)
====================================================================================================

======== Exception caught by gestures library ======================================================
The following assertion was thrown while handling a pointer data packet:
'package:flutter/src/rendering/mouse_tracker.dart': Failed assertion: line 205 pos 12: '!_debugDuringDeviceUpdate': is not true.


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.yml

When the exception was thrown, this was the stack: 
#2      MouseTracker._deviceUpdatePhase (package:flutter/src/rendering/mouse_tracker.dart:205:12)
#3      MouseTracker.updateWithEvent.<anonymous closure> (package:flutter/src/rendering/mouse_tracker.dart:328:7)
#4      MouseTracker._monitorMouseConnection (package:flutter/src/rendering/mouse_tracker.dart:193:9)
#5      MouseTracker.updateWithEvent (package:flutter/src/rendering/mouse_tracker.dart:327:5)
#6      RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:326:20)
#7      GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:413:7)
#8      GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:376:5)
#9      GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:323:7)
#10     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:292:9)
#11     _invoke1 (dart:ui/hooks.dart:186:13)
#12     PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:424:7)
#13     _dispatchPointerDataPacket (dart:ui/hooks.dart:119:31)
(elided 2 frames from class _AssertionError)

 所以添加一个宽高就好了:

这篇关于flutter报错Cannot hit test a render box that has never been laid out的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/613489

相关文章

解决systemctl reload nginx重启Nginx服务报错:Job for nginx.service invalid问题

《解决systemctlreloadnginx重启Nginx服务报错:Jobfornginx.serviceinvalid问题》文章描述了通过`systemctlstatusnginx.se... 目录systemctl reload nginx重启Nginx服务报错:Job for nginx.javas

VMWare报错“指定的文件不是虚拟磁盘“或“The file specified is not a virtual disk”问题

《VMWare报错“指定的文件不是虚拟磁盘“或“Thefilespecifiedisnotavirtualdisk”问题》文章描述了如何修复VMware虚拟机中出现的“指定的文件不是虚拟... 目录VMWare报错“指定的文件不是虚拟磁盘“或“The file specified is not a virt

使用Vue.js报错:ReferenceError: “Vue is not defined“ 的原因与解决方案

《使用Vue.js报错:ReferenceError:“Vueisnotdefined“的原因与解决方案》在前端开发中,ReferenceError:Vueisnotdefined是一个常见... 目录一、错误描述二、错误成因分析三、解决方案1. 检查 vue.js 的引入方式2. 验证 npm 安装3.

PHP执行php.exe -v命令报错的解决方案

《PHP执行php.exe-v命令报错的解决方案》:本文主要介绍PHP执行php.exe-v命令报错的解决方案,文中通过图文讲解的非常详细,对大家的学习或工作有一定的帮助,需要的朋友可以参考下... 目录执行phpandroid.exe -v命令报错解决方案执行php.exe -v命令报错-PHP War

鸿蒙开发搭建flutter适配的开发环境

《鸿蒙开发搭建flutter适配的开发环境》文章详细介绍了在Windows系统上如何创建和运行鸿蒙Flutter项目,包括使用flutterdoctor检测环境、创建项目、编译HAP包以及在真机上运... 目录环境搭建创建运行项目打包项目总结环境搭建1.安装 DevEco Studio NEXT IDE

CentOS系统使用yum命令报错问题及解决

《CentOS系统使用yum命令报错问题及解决》文章主要讲述了在CentOS系统中使用yum命令时遇到的错误,并提供了个人解决方法,希望对大家有所帮助,并鼓励大家支持脚本之家... 目录Centos系统使用yum命令报错找到文件替换源文件为总结CentOS系统使用yum命令报错http://www.cppc

Flutter 进阶:绘制加载动画

绘制加载动画:由小圆组成的大圆 1. 定义 LoadingScreen 类2. 实现 _LoadingScreenState 类3. 定义 LoadingPainter 类4. 总结 实现加载动画 我们需要定义两个类:LoadingScreen 和 LoadingPainter。LoadingScreen 负责控制动画的状态,而 LoadingPainter 则负责绘制动画。

Jenkins 插件 地址证书报错问题解决思路

问题提示摘要: SunCertPathBuilderException: unable to find valid certification path to requested target...... 网上很多的解决方式是更新站点的地址,我这里修改了一个日本的地址(清华镜像也好),其实发现是解决不了上述的报错问题的,其实,最终拉去插件的时候,会提示证书的问题,几经周折找到了其中一遍博文

论文翻译:ICLR-2024 PROVING TEST SET CONTAMINATION IN BLACK BOX LANGUAGE MODELS

PROVING TEST SET CONTAMINATION IN BLACK BOX LANGUAGE MODELS https://openreview.net/forum?id=KS8mIvetg2 验证测试集污染在黑盒语言模型中 文章目录 验证测试集污染在黑盒语言模型中摘要1 引言 摘要 大型语言模型是在大量互联网数据上训练的,这引发了人们的担忧和猜测,即它们可能已

Flutter Button使用

Material 组件库中有多种按钮组件如ElevatedButton、TextButton、OutlineButton等,它们的父类是于ButtonStyleButton。         基本的按钮特点:         1.按下时都会有“水波文动画”。         2.onPressed属性设置点击回调,如果不提供该回调则按钮会处于禁用状态,禁用状态不响应用户点击。