gpt4 book ai didi

flutter - 我怎样才能像 child 一样使用 CustomScrollView

转载 作者:行者123 更新时间:2023-12-03 02:50:14 25 4
gpt4 key购买 nike

我是一个刚接触 Flutter 的新手。

我想使用 CustomScrollView 作为 Row/Column Widget 的子级

当 CustomScrollView 是 root 时,它工作得很好。但是,一旦我将它放入 Row Widget 的子项中,它就会报错。

不能将 CustomScrollview 用作 Row 小部件的子项吗?如果是,请告诉我原因,最好的选择是什么?

或者,如果我的代码有错误,我希望你能更正它。

What I want to make

my CustomScrollViewWidget

我不知道这是不是你想要的,但这是我的错误。

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during performLayout():
'package:flutter/src/rendering/viewport.dart': Failed assertion: line 1758 pos 16:
'constraints.hasBoundedHeight': 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=BUG.md
The relevant error-causing widget was:
CustomScrollView



The following RenderObject was being processed when the exception was fired: RenderShrinkWrappingViewport#0344f relayoutBoundary=up14 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
needs compositing
creator: ShrinkWrappingViewport ← IgnorePointer-[GlobalKey#e4530] ← Semantics ← _PointerListener ←
Listener ← _GestureSemantics ←
RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#a61b3] ← _PointerListener ← Listener
← _ScrollableScope ← _ScrollSemantics-[GlobalKey#42b3c] ← RepaintBoundary ← ⋯
parentData: <none> (can use size)
constraints: BoxConstraints(unconstrained)
size: MISSING
axisDirection: right
crossAxisDirection: down
offset: ScrollPositionWithSingleContext#46fe1(offset: 0.0, range: null..null, viewport: null,
ScrollableState, ClampingScrollPhysics -> RangeMaintainingScrollPhysics, IdleScrollActivity#66c28,
ScrollDirection.idle)
This RenderObject had the following child:
child 0: RenderSliverList#42dfb NEEDS-LAYOUT NEEDS-PAINT
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderShrinkWrappingViewport#0344f relayoutBoundary=up14 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1702 pos 12: 'hasSize'
The relevant error-causing widget was
CustomScrollView
lib\0. TestCode.dart:31
════════════════════════════════════════════════════════════════════════════════

这是我的代码!

class WrapVisit extends StatefulWidget {
WrapVisitState createState() => WrapVisitState();
}

class WrapVisitState extends State<WrapVisit> {
@override
Widget build(BuildContext context) {
return new Container(
padding: EdgeInsets.all(10),
color: Colors.white,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
new Text(
"브랜드관",
textAlign: TextAlign.left,
style: TextStyle(fontWeight: FontWeight.bold),
),
new Container(
margin: EdgeInsets.all(5),
child: new Text(
"전체보기",
textAlign: TextAlign.right,
style: TextStyle(
fontSize: 10,
color: Colors.black,
),
),
),
CustomScrollView(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
slivers: [
SliverList(
delegate: SliverChildListDelegate(
[
... SliverListChildWidgets ...
],
),
),
],
),
],
),
],
),
);
}
}

最佳答案

Column 不喜欢无限制高度的 child 。要修复它,请将 CustomScrollViewshr​​inkWrap 参数设置为 true

关于flutter - 我怎样才能像 child 一样使用 CustomScrollView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64516009/

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