ChildScrollView内没有ListView是不可能的吗

ChildScrollView内没有ListView是不可能的吗

本文介绍了在SingleChildScrollView内没有ListView是不可能的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否不可能在 SingleChildScrollView 中包含 ListView ?我们试图创建三个按钮,它们的作用类似于单选按钮.我们已经从

Is it impossible to have ListView inside SingleChildScrollView? We trying to create three button which work like radio group button. We have found the solution from Flutter : Custom Radio Button.

But in our case, it is wrapped by 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],
                            ),
                          );
                        },
                      )
                    ],
                  )
                ]))

Error

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
解决方案

Surround you ListView with Expanded widget.

You can't have a scrollable widget inside another scrollable widget without setting a proper height for the inner one.

Or use ConstrainedBox

这篇关于在SingleChildScrollView内没有ListView是不可能的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 22:18