繁体   English   中英

如何在 flutter 的 SingleChildScrollView 中使用 Listview?

[英]How to use Listview in SingleChildScrollView in flutter?

我需要在 SingleChildScrollView 小部件中使用 3 个水平 ListView。 但什么都没有显示。 我将这些代码用于 ListViews 之一:

Scaffold(
    body: new SingleChildScrollView(
  primary: true,
  child: new Column(
    mainAxisSize: MainAxisSize.min,
    children: [
      new ListView.builder(
          primary: false,
          shrinkWrap: true,
          physics: const NeverScrollableScrollPhysics(),
          itemCount: _categoryModel.length,
          scrollDirection: Axis.horizontal,
          itemBuilder: (context, index) => new Card(
            child: new Center(
              child: Padding(
                padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 16),
                child: new Text(_categoryModel[index].title),
              ),
            ),
          ))
    ],
  ),
))

如何在不使用具有高度的容器的情况下修复此错误?

尝试用Expanded包装你的ListView

用这个:

 Scaffold(
        body: new SingleChildScrollView(
      
      child: new Container(
        child:      new ListView.builder(
              primary: false,
              shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              itemCount: _categoryModel.length,
              scrollDirection: Axis.horizontal,
              itemBuilder: (context, index) => new Card(
                child: new Center(
                  child: Padding(
                    padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 16),
                    child: new Text(_categoryModel[index].title),
                  ),
                ),
              ))
       
      ),
    ))

使用 Wrap 小部件而不是 ListView。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM