首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我如何从小使用CustomScrollView

我如何从小使用CustomScrollView
EN

Stack Overflow用户
提问于 2020-10-25 01:07:29
回答 2查看 303关注 0票数 2

我是个刚开始玩扑扑的新手。

我想使用CustomScrollView作为行/列小部件的子级

当CustomScrollView是根目录时,它工作得很好。但是,当我把它放入Row Widget的孩子中时,它就出现了一个错误。

CustomScrollview不能用作行小部件的子级吗?如果是,请告诉我原因,最好的替代方案是什么?

或者,如果我的代码中有错误,我希望您纠正它。

What I want to make

my CustomScrollViewWidget

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

代码语言:javascript
复制
══╡ 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
════════════════════════════════════════════════════════════════════════════════

这是我的代码!

代码语言:javascript
复制
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 ...
                      ],
                    ),
                  ),
                ],
              ),
            ],
          ),
        ],
      ),
    );
  }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-10-25 12:41:27

您需要首先将滚动视图包装在一个大小的框或容器中。它需要一个具有设置尺寸的父级。有几个小部件在行/列中不起作用,除非您首先将它们放入一个大小的父级中。

票数 2
EN

Stack Overflow用户

发布于 2020-10-25 03:05:44

Column不喜欢身高不受限制的孩子。要修复它,请将CustomScrollViewshrinkWrap参数设置为true

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64516009

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档