首页 > 解决方案 > RenderListWheelViewport 对象在布局期间被赋予无限大小

问题描述

我正在使用ListWheelScrollViewWidget 为我的列表项提供滚动效果,但出现上述错误。我只想在单个列表项中显示带有一些图像和文本的堆叠项,并为它们提供 3D Wheeling 效果。

下面是我的代码->

class ExploreWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _ExploreState();
}

class _ExploreState extends State<ExploreWidget> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: null,
      body: Column(
        children: <Widget>[
          _header(),
          _exploreList()
        ],
      )
    );

  }

  Widget _header(){
    return SizedBox(
      height: 200,
      width: 800,
    );

  }

  Widget _exploreList(){
    return ListWheelScrollView.useDelegate(
      itemExtent: 75,
      childDelegate: ListWheelChildBuilderDelegate(
        builder:(context,index){
          return Container(
            height: 500,
            width: 800,
            child: Stack(
              children: <Widget>[
                Image(image: AssetImage(
                  _products[index].image
                )),
                Text(_products[index].name,style: Style.sectionTitleWhite,),
                Text('70% off',style: Style.cardListTitleWhite,),
              ],
            ),
          );
        }
      ),
    );
  }

}

标签: flutterdartdelegatesflutter-layoutinfinite

解决方案


由于_exploreList()小部件的实现方式而发生错误。这个小部件被包裹在里面Column,它本身不会滚动。此外,您正在返回一个ScrollView具有无限大小的。因此它抛出了上述错误。要解决此问题,请将_exploreList()小部件包裹在Flexible其中只占用最少的可用空间来呈现和滚动。下面的工作示例代码:

body: Column(
          children: <Widget>[
            _header(),
            Flexible(
              child: _exploreList()
            )
          ],
        )

现在你应该可以WheelScrollView正常使用了。

在此处输入图像描述


推荐阅读