祝你有个美好的一天。我正在努力将 ListView.builder 包装在一个列中。 每次我尝试修复它时,我都会收到此异常:
The following RenderObject was being processed when the exception was fired:
flutter: RenderViewport#c3792 NEEDS-LAYOUT NEEDS-PAINT
flutter: creator: Viewport ← IgnorePointer-[GlobalKey#b696d] ← Semantics ← Listener ← _GestureSemantics ←
flutter: RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#65964] ← Listener ← _ScrollableScope
flutter: ← _ScrollSemantics-[GlobalKey#f3a27] ← Scrollable ← PrimaryScrollController ← ListView ← ⋯
flutter: parentData: <none> (can use size)
flutter: constraints: BoxConstraints(w=327.0, 0.0<=h<=Infinity)
flutter: size: MISSING
flutter: axisDirection: down
flutter: crossAxisDirection: right
flutter: offset: ScrollPositionWithSingleContext#60171(offset: 0.0, range: null..null, viewport: null,
flutter: ScrollableState, AlwaysScrollableScrollPhysics -> BouncingScrollPhysics, IdleScrollActivity#63b9f,
flutter: ScrollDirection.idle)
flutter: anchor: 0.0
flutter: This RenderObject had the following descendants (showing up to depth 5):
flutter: RenderSliverPadding#e4dfb NEEDS-LAYOUT NEEDS-PAINT
flutter: RenderSliverList#17862 NEEDS-LAYOUT NEEDS-PAINT
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: Another exception was thrown: RenderBox was not laid out: RenderViewport#c3792 NEEDS-LAYOUT NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderViewport#c3792 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderIgnorePointer#8fccb relayoutBoundary=up9 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderFlex#cbeea relayoutBoundary=up2 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderPadding#0b306 relayoutBoundary=up1 NEEDS-PAINT
flutter: Another exception was thrown: NoSuchMethodError: The method '<=' was called on null.
flutter: Another exception was thrown: NoSuchMethodError: The getter 'visible' was called on null.
flutter: Another exception was thrown: NoSuchMethodError: The method '<=' was called on null.
flutter: Another exception was thrown: NoSuchMethodError: The method '<=' was called on null.
flutter: Another exception was thrown: NoSuchMethodError: The method '<=' was called on null.
flutter: Another exception was thrown: NoSuchMethodError: The method '<=' was called on null.
这是我的代码:
Padding(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: ListView.builder(
itemCount: _messages.length,
itemBuilder: (context, position) {
print(_messages.length);
return Center(child: Text(_messages[position]));
}),
)
]))
如果有人能帮助我,我将不胜感激。
最佳答案
正如我在评论中提到的,将第二个 Padding
包裹在 Expanded
中小部件完成这项工作。
关于android - 在 Column 中包装一个 listviewBuilder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56329086/