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

这篇具有很好参考价值的文章主要介绍了flutter报错Cannot hit test a render box that has never been laid out。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

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

flutter报错Cannot hit test a render box that has never been laid out,多端开发,flutter

就导致了那个错误:

flutter报错Cannot hit test a render box that has never been laid out,多端开发,flutter

======== 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,多端开发,flutter文章来源地址https://www.toymoban.com/news/detail-806411.html

到了这里,关于flutter报错Cannot hit test a render box that has never been laid out的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 解决Vue Uniapp中[Vue warn]: Error in render: “TypeError: Cannot read properties of undefined 报错

     在页面元素进行v-for循环遍历时通过 a.b.c 方式找到后台中的数据,解析完成后,页面正常渲染,但是控制台报错. 这是因为 js是解释型语言,读取一行,加载一样 所以页面的加载,比发送请求要快,要早 请求数据虽然放在了created中,但是请求数据是异步的,需要时间。 也

    2024年02月11日
    浏览(65)
  • Vue报错解决[Vue warn]: Error in render: “TypeError: Cannot read property ‘state‘ of undefined“

    Vue2项目中报错: [Vue warn]: Error in render: “TypeError: Cannot read property ‘state’ of undefined” [Vue warn]: Error in mounted hook: “TypeError: Cannot read property ‘dispatch’ of undefined” 这个错误提示通常出现在 Vue 组件中,它尝试读取 Vuex store 的 state 对象,但是该对象没有被定义。这可能是由以

    2024年02月10日
    浏览(60)
  • 【解决报错selenium-python】AttributeError: ‘Test_ActionChains‘ object has no attribute ‘driver‘

    Python-selenium自动化测试脚本报错 AttributeError: ‘Test_ActionChains’ object has no attribute ‘driver’ 解决方法 在编代码的时候几次遇到同样的问提,找到解决方案后发现在自己不注意一些小问题而浪费了很多时间,这个问题就是其一 小伙伴们猜猜我哪里写错了,我要开始剧透了噢~

    2024年02月11日
    浏览(58)
  • 报错解决:Cannot call sendError() after the response has been committed

    报错背景:   在做开源项目《瑞吉外卖》时,编写拦截器代码后,前端登录时,后端报错如下:            思考与思路:          Cannot call sendError() after the response has been committed.....意思是,当response已经提交后,不能再sendError()。那也就是说,我在代码中一定是

    2024年02月11日
    浏览(44)
  • Unity寻路报错“SetDestination“ can only be called on an active agent that has been placed on a NavMesh.

    这个报错表示NavMeshAgent所在节点未放置在寻路网格上。出现这个错误一般伴有 \\\"Failed to create agent because it is not close enough to the NavMesh\\\"类似警告。 表明寻路代理创建失败,后续设置目的地肯定就会导致失败。 出现此类问题需要检查: 在调用SetDestination的时候,NavMeshAgent是否启用

    2023年04月08日
    浏览(45)
  • 【Git】删除本地分支;报错error: Cannot delete branch ‘wangyunuo-test‘ checked out at ‘XXX‘

    目录 0.环境 1.问题描述 2.解决步骤 1)使用命令切换到其他分支 2)查看当前本地所有分支 3)删除“wangyunuo-test”分支 windows 11 64位 + Git + VScode跑代码 在做项目过程中,想删除一个本地分支“wangyunuo-test”,使用的是以下的命令删除(目前我在这个分支上) 但是删除后会报错

    2024年02月09日
    浏览(42)
  • spark 发送数据到 kafka 报错:Cannot Perform operation after producer has been closed

    spark发送到kafka是有生产者线程池的. 这个支持的过期策略在spark2.4.4之前的策略是: 你task access该producer开始计时. 如果10min内没有新的access则close该producer. 那么问题就是: 小数据量,做完还回去,不同task接力刷洗 池子里producer对象的access时间,那么过期不了. 如果你task拿到后 10min都

    2024年02月05日
    浏览(46)
  • 【软件测试】黑盒测试black box testing

    又称为功能测试function testing、行为测试behavior testing 黑盒测试测试不知道代码细节的软件 Black box testing test software without knowing how it is coded. 测试目的:判断输入和输出是否符合软件要求 1. 不需要知道代码细节 2. 相互独立 3. 可以在说明书完成后就设计测试用例,不用等代码完

    2024年04月23日
    浏览(41)
  • cesium:error:An error occurred while rendering. Rendering has stopped.

    问题情景:配置环境node.js+npm+cesium时,出现如下问题:  根据教程和搜索都没有看到相关解答,检查控制台error  翻译发现时数据读取有问题 根据官网文档测试,浏览器端没有问题,html前端架构也没问题,最终锁定在脚本引入,即script和css文件,css主样式,布局没乱, 比对官

    2024年02月13日
    浏览(56)
  • 【Flutter】运行报错:Cannot run with sound null safety, because the following dependencies

    flutter 在运行老项目的时候,或者是添加一些第三方库的时候,会报 Cannot run with sound null safety, because the following dependencies don‘t support null safety; 报错是因为这些包不支持safety模式。 解决方法: 运行的时候添加–no-sound-null-safety Android Studio工具 选择【Run】 --【 Edit Configuration

    2024年02月12日
    浏览(49)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包