gpt4 book ai didi

flutter - 水平 ListView 流

转载 作者:行者123 更新时间:2023-12-05 07:29:30 25 4
gpt4 key购买 nike

我在从 Firebase 创建水平 ListView 流时遇到问题。

这是我的代码:

...
Column(
children: [
Container(
height: 200.0,
child: StreamBuilder(
stream: Firestore.instance
.collection('users')
.snapshots(),
builder: (context, snapshot) {
int length = 0;
if(snapshot.hasData && snapshot.data.documents != null)
length = (snapshot.data.documents.length ?? 0);
return ListView.builder(
itemCount: length,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
return ListItemWidget(document: snapshot.data.documents[index],);
},
);
},
),
),
],
),
...

我得到这个错误:

I/flutter (28131): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (28131): The following assertion was thrown during performResize():
I/flutter (28131): Horizontal viewport was given unbounded width.
I/flutter (28131): Viewports expand in the scrolling direction to fill their container.In this case, a horizontal
I/flutter (28131): viewport was given an unlimited amount of horizontal space in which to expand. This situation
I/flutter (28131): typically happens when a scrollable widget is nested inside another scrollable widget.
I/flutter (28131): If this widget is always nested in a scrollable widget there is no need to use a viewport because
I/flutter (28131): there will always be enough horizontal space for the children. In this case, consider using a Row
I/flutter (28131): instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
I/flutter (28131): the width of the viewport to the sum of the widths of its children.
I/flutter (28131): When the exception was thrown, this was the stack:
I/flutter (28131): #0 RenderViewport.performResize.<anonymous closure> (package:flutter/src/rendering/viewport.dart:1159:15)
I/flutter (28131): #1 RenderViewport.performResize (package:flutter/src/rendering/viewport.dart:1186:6)
I/flutter (28131): #2 RenderObject.layout (package:flutter/src/rendering/object.dart:1616:9)
I/flutter (28131): #3 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (28131): #4 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (28131): #5 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (28131): #6 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (28131): #7 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (28131): #8 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (28131): #9 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (28131): #10 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (28131): #11 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (28131): #12 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (28131): #13 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (28131): #14 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (28131): #15 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (28131): #16 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (28131): #17 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (28131): #18 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (28131): #19 RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:262:13)
I/flutter (28131): #20 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (28131): #21 RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:199:11)
I/flutter (28131): #22 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (28131): #23 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (28131): #24 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (28131): #25 RenderSliverList.performLayout (package:flutter/src/rendering/sliver_list.dart:164:27)
I/flutter (28131): #26 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (28131): #27 RenderSliverPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:182:11)
I/flutter (28131): #28 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (28131): #29 RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:405:13)
I/flutter (28131): #30 RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1320:12)
I/flutter (28131): #31 RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1238:20)
I/flutter (28131): #32 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1506:7)
I/flutter (28131): #33 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:765:18)
I/flutter (28131): #34 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:270:19)
I/flutter (28131): #35 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:654:13)
I/flutter (28131): #36 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:208:5)
I/flutter (28131): #37 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter (28131): #38 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter (28131): #39 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter (28131): #40 _invoke (dart:ui/hooks.dart:128:13)
I/flutter (28131): #41 _drawFrame (dart:ui/hooks.dart:117:3)
I/flutter (28131): The following RenderObject was being processed when the exception was fired:
I/flutter (28131): RenderViewport#4cfa1 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (28131): creator: Viewport ← _ScrollableScope ← IgnorePointer-[GlobalKey#a76da] ← Semantics ← Listener ←
I/flutter (28131): _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#8a47c] ←
I/flutter (28131): _ScrollSemantics-[GlobalKey#cab19] ← RepaintBoundary ← CustomPaint ← RepaintBoundary ←
I/flutter (28131): NotificationListener<ScrollNotification> ← ⋯
I/flutter (28131): parentData: <none> (can use size)
I/flutter (28131): constraints: BoxConstraints(0.0<=w<=Infinity, h=300.0)
I/flutter (28131): size: MISSING
I/flutter (28131): axisDirection: right
I/flutter (28131): crossAxisDirection: down
I/flutter (28131): offset: ScrollPositionWithSingleContext#8dfac(offset: 0.0, range: null..null, viewport: null,
I/flutter (28131): ScrollableState, ClampingScrollPhysics, IdleScrollActivity#91939, ScrollDirection.idle)
I/flutter (28131): anchor: 0.0
I/flutter (28131): This RenderObject had the following descendants (showing up to depth 5):
I/flutter (28131): RenderSliverPadding#e80f1 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (28131): RenderSliverList#97084 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (28131): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderViewport#4cfa1 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderViewport#4cfa1 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderIgnorePointer#df1eb relayoutBoundary=up13 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#44b85 relayoutBoundary=up12 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderPointerListener#96b35 relayoutBoundary=up11 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#80416 relayoutBoundary=up10 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: _RenderScrollSemantics#712c9 relayoutBoundary=up9 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#aaf0f relayoutBoundary=up8 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderCustomPaint#a9537 relayoutBoundary=up7 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: BoxConstraints forces an infinite width.
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: _RenderListTile#6d051 relayoutBoundary=up9 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderPadding#9ebbd relayoutBoundary=up8 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#0673a relayoutBoundary=up7 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderPointerListener#4ee5a relayoutBoundary=up6 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#36efb relayoutBoundary=up5 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderFlex#3f9fc relayoutBoundary=up4 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: BoxConstraints forces an infinite width.
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: _RenderListTile#fb3c8 relayoutBoundary=up9 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderPadding#db36b relayoutBoundary=up8 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#56680 relayoutBoundary=up7 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderPointerListener#9a367 relayoutBoundary=up6 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#f9ea9 relayoutBoundary=up5 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderFlex#18660 relayoutBoundary=up4 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: 'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 441 pos 12: 'child.hasSize': is not true.
I/flutter (28131): Another exception was thrown: Horizontal viewport was given unbounded width.
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderViewport#e06d5 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderViewport#e06d5 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderIgnorePointer#c9f49 relayoutBoundary=up13 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#710fd relayoutBoundary=up12 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderPointerListener#40679 relayoutBoundary=up11 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#89057 relayoutBoundary=up10 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: _RenderScrollSemantics#fa9df relayoutBoundary=up9 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#153a7 relayoutBoundary=up8 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderCustomPaint#31069 relayoutBoundary=up7 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#ba7c8 relayoutBoundary=up6 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: BoxConstraints forces an infinite width.
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: _RenderListTile#e1115 relayoutBoundary=up9 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderPadding#ba1c6 relayoutBoundary=up8 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#f49e3 relayoutBoundary=up7 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderPointerListener#28bc1 relayoutBoundary=up6 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#7e4cc relayoutBoundary=up5 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderFlex#30f31 relayoutBoundary=up4 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: BoxConstraints forces an infinite width.
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: _RenderListTile#75a70 relayoutBoundary=up9 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderPadding#7e571 relayoutBoundary=up8 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#9dbc1 relayoutBoundary=up7 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderPointerListener#59637 relayoutBoundary=up6 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#cbb7b relayoutBoundary=up5 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderFlex#ca6b6 relayoutBoundary=up4 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: 'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 441 pos 12: 'child.hasSize': is not true.
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#ba7c8 relayoutBoundary=up6 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: NoSuchMethodError: The method '<=' was called on null.
I/flutter (28131): Another exception was thrown: 'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 441 pos 12: 'child.hasSize': is not true.
I/flutter (28131): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#687b9 relayoutBoundary=up6 NEEDS-PAINT
I/flutter (28131): Another exception was thrown: NoSuchMethodError: The method '<=' was called on null.
I/flutter (28131): Another exception was thrown: 'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 441 pos 12: 'child.hasSize': is not true.
I/flutter (28131): Another exception was thrown: NoSuchMethodError: The getter 'visible' was called on null.
I/flutter (28131): Another exception was thrown: Multiple widgets used the same GlobalKey.
I/flutter (28131): Another exception was thrown: Multiple widgets used the same GlobalKey.
I/flutter (28131): Another exception was thrown: Multiple widgets used the same GlobalKey.
E/flutter (28131): [ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception:
E/flutter (28131): Cannot hit test a render box with no size.
E/flutter (28131): The hitTest() method was called on this RenderBox:
E/flutter (28131): RenderRepaintBoundary#a0721 relayoutBoundary=up3 NEEDS-PAINT
E/flutter (28131): Although this node is not marked as needing layout, its size is not set. A RenderBox object must have an explicit size before it can be hit-tested. Make sure that the RenderBox in question sets its size during layout.
E/flutter (28131): #0 RenderBox.hitTest.<anonymous closure> (package:flutter/src/rendering/box.dart:1911:9)
E/flutter (28131): #1 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1922:6)
E/flutter (28131): #2 _RenderSliverMultiBoxAdaptor&RenderSliver&ContainerRenderObjectMixin&RenderSliverHelpers.hitTestBoxChild (package:flutter/src/rendering/sliver.dart:1471:22)
E/flutter (28131): #3 RenderSliverMultiBoxAdaptor.hitTestChildren (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:455:11)
E/flutter (28131): #4 RenderSliver.hitTest (package:flutter/src/rendering/sliver.dart:1137:11)
E/flutter (28131): #5 RenderSliverPadding.hitTestChildren (package:flutter/src/rendering/sliver_padding.dart:266:20)
E/flutter (28131): #6 RenderSliver.hitTest (package:flutter/src/rendering/sliver.dart:1137:11)
E/flutter (28131): #7 RenderViewportBase.hitTestChildren (package:flutter/src/rendering/viewport.dart:572:43)
E/flutter (28131): #8 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #9 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
E/flutter (28131): #10 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #11 RenderIgnorePointer.hitTest (package:flutter/src/rendering/proxy_box.dart:2780:37)
E/flutter (28131): #12 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
E/flutter (28131): #13 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #14 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
E/flutter (28131): #15 RenderProxyBoxWithHitTestBehavior.hitTest (package:flutter/src/rendering/proxy_box.dart:164:19)
E/flutter (28131): #16 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
E/flutter (28131): #17 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #18 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
E/flutter (28131): #19 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #20 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
E/flutter (28131): #21 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #22 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
E/flutter (28131): #23 RenderCustomPaint.hitTestChildren (package:flutter/src/rendering/custom_paint.dart:500:18)
E/flutter (28131): #24 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #25 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
E/flutter (28131): #26 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #27 _RenderFlex&RenderBox&ContainerRenderObjectMixin&RenderBoxContainerDefaultsMixin.defaultHitTestChildren (package:flutter/src/rendering/box.dart:2250:17)
E/flutter (28131): #28 RenderFlex.hitTestChildren (package:flutter/src/rendering/flex.dart:925:12)
E/flutter (28131): #29 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #30 _RenderStack&RenderBox&ContainerRenderObjectMixin&RenderBoxContainerDefaultsMixin.defaultHitTestChildren (package:flutter/src/rendering/box.dart:2250:17)
E/flutter (28131): #31 RenderStack.hitTestChildren (package:flutter/src/rendering/stack.dart:595:12)
E/flutter (28131): #32 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #33 _RenderCustomMultiChildLayoutBox&RenderBox&Cont
E/flutter (28131): [ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception:
E/flutter (28131): Cannot hit test a render box with no size.
E/flutter (28131): The hitTest() method was called on this RenderBox:
E/flutter (28131): RenderRepaintBoundary#a0721 relayoutBoundary=up3 NEEDS-PAINT
E/flutter (28131): Although this node is not marked as needing layout, its size is not set. A RenderBox object must have an explicit size before it can be hit-tested. Make sure that the RenderBox in question sets its size during layout.
E/flutter (28131): #0 RenderBox.hitTest.<anonymous closure> (package:flutter/src/rendering/box.dart:1911:9)
E/flutter (28131): #1 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1922:6)
E/flutter (28131): #2 _RenderSliverMultiBoxAdaptor&RenderSliver&ContainerRenderObjectMixin&RenderSliverHelpers.hitTestBoxChild (package:flutter/src/rendering/sliver.dart:1471:22)
E/flutter (28131): #3 RenderSliverMultiBoxAdaptor.hitTestChildren (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:455:11)
E/flutter (28131): #4 RenderSliver.hitTest (package:flutter/src/rendering/sliver.dart:1137:11)
E/flutter (28131): #5 RenderSliverPadding.hitTestChildren (package:flutter/src/rendering/sliver_padding.dart:266:20)
E/flutter (28131): #6 RenderSliver.hitTest (package:flutter/src/rendering/sliver.dart:1137:11)
E/flutter (28131): #7 RenderViewportBase.hitTestChildren (package:flutter/src/rendering/viewport.dart:572:43)
E/flutter (28131): #8 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #9 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
E/flutter (28131): #10 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #11 RenderIgnorePointer.hitTest (package:flutter/src/rendering/proxy_box.dart:2780:37)
E/flutter (28131): #12 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
E/flutter (28131): #13 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #14 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
E/flutter (28131): #15 RenderProxyBoxWithHitTestBehavior.hitTest (package:flutter/src/rendering/proxy_box.dart:164:19)
E/flutter (28131): #16 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
E/flutter (28131): #17 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #18 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
E/flutter (28131): #19 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #20 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
E/flutter (28131): #21 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #22 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
E/flutter (28131): #23 RenderCustomPaint.hitTestChildren (package:flutter/src/rendering/custom_paint.dart:500:18)
E/flutter (28131): #24 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #25 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:117:19)
E/flutter (28131): #26 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #27 _RenderFlex&RenderBox&ContainerRenderObjectMixin&RenderBoxContainerDefaultsMixin.defaultHitTestChildren (package:flutter/src/rendering/box.dart:2250:17)
E/flutter (28131): #28 RenderFlex.hitTestChildren (package:flutter/src/rendering/flex.dart:925:12)
E/flutter (28131): #29 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #30 _RenderStack&RenderBox&ContainerRenderObjectMixin&RenderBoxContainerDefaultsMixin.defaultHitTestChildren (package:flutter/src/rendering/box.dart:2250:17)
E/flutter (28131): #31 RenderStack.hitTestChildren (package:flutter/src/rendering/stack.dart:595:12)
E/flutter (28131): #32 RenderBox.hitTest (package:flutter/src/rendering/box.dart:1924:11)
E/flutter (28131): #33 _RenderCustomMultiChildLayoutBox&RenderBox&Cont

但是,如果我使用 scrollDirection: Axis.vertical 而不是 Axis.horizo​​ntal,它就可以正常工作。或者,如果我像这样使用常规 ListView,它也可以工作:

...
Column(
children: [
Container(
height: 200.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
Container(width: 160.0, color: Colors.red,),
Container(width: 160.0, color: Colors.orange,),
Container(width: 160.0, color: Colors.pink,),
Container(width: 160.0, color: Colors.yellow,),
],
),
),
],
),
...

这感觉像是一个愚蠢的问题,但我不知道我做错了什么。

最佳答案

此问题的原因是 ListView 的宽度不受限制。由于小部件水平滚动,因此应定义有限宽度。当小部件无法填充屏幕上的有限尺寸时,会发生此错误。您可以在 ListView 上设置宽度或尝试使用 Expanded小部件。

要获取屏幕的宽度尺寸,您可以使用 LayoutBuilderMediaQuery .

关于flutter - 水平 ListView 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52722128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com