flutter报错Cannot hit test a render box that has never been laid out
出现这个问题的原因可能是因为你把一个ListView或者GridView放到了一个没有设置大小的容器里面导致的,所以意思是不能渲染那一个没有布局过的容器。我这里遇到的错误是因为我把GridView放到了一个Container里面,并且我没有设置Container宽高。
出现这个问题的原因可能是因为你把一个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.ymlWhen 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)
所以添加一个宽高就好了:
更多推荐
所有评论(0)