在SingleChildScrollView内是否有ListView是不可能的?

时间:2019-09-11 16:05:46

标签: listview flutter dart

是否不可能在ListView中包含SingleChildScrollView?我们试图创建三个按钮,它们的作用类似于单选按钮。我们从Flutter : Custom Radio Button 找到了解决方案。

但是在我们的情况下,它由SingleChildScrollView包裹。

  body: SingleChildScrollView(
            padding: const EdgeInsets.all(8.0),
            child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Row(
                    children: <Widget>[
                      Text(
                        Localization.of(context).priority,
                        style: TextStyle(fontSize: 15.0),
                      ),
                      ListView.builder(
                        scrollDirection: Axis.vertical,
                        shrinkWrap: true,
                        itemCount: sampleData.length,
                        itemBuilder: (BuildContext context, int index) {
                          return InkWell(
                            child: RadioItem(
                              sampleData[index],
                            ),
                          );
                        },
                      )
                    ],
                  )
                ]))

错误

The following RenderObject was being processed when the exception was fired: RenderShrinkWrappingViewport#4d85f relayoutBoundary=up27 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
RenderObject: RenderShrinkWrappingViewport#4d85f relayoutBoundary=up27 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
    needs compositing
    parentData: <none> (can use size)
    constraints: BoxConstraints(unconstrained)
    size: MISSING
    axisDirection: down
    crossAxisDirection: right
    offset: ScrollPositionWithSingleContext#fa7e6(offset: 0.0, range: null..null, viewport: null, ScrollableState, AlwaysScrollableScrollPhysics -> ClampingScrollPhysics, IdleScrollActivity#d2e68, ScrollDirection.idle)
    child 0: RenderSliverPadding#37bf3 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
        parentData: layoutOffset=0.0
        constraints: MISSING
        geometry: null
        padding: EdgeInsets.zero
        textDirection: ltr

1 个答案:

答案 0 :(得分:2)

使用ListView小部件包围Expanded

在没有为内部可滚动部件设置适当的高度的情况下,您不能在另一个可滚动部件中使用可滚动部件。

或使用ConstrainedBox

sample