【问题标题】:How to make listview scroll with SingleChildScrollView in flutter如何在颤动中使用 SingleChildScrollView 使列表视图滚动
【发布时间】:2020-10-12 12:04:52
【问题描述】:

我把ListView 放在SingleChildScrollView 里面,把listview 放在Wrap 里面,所以我想用SingleChildScrollView 让listview 滚动 这是listView

Padding(
  padding: EdgeInsets.only(top: 10.0 ,right: 30.0 , left: 30.0),
  child: Center(
    child: Wrap(
      children: <Widget>[
        Container(
          child:ListView.builder(
            scrollDirection: Axis.vertical,
            shrinkWrap: true,
            itemCount: items.length,
            itemBuilder: (context,index){
              return Align(
                child: Container(
                  padding: EdgeInsets.only(top: 20.0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      Container(
                        child: Padding(
                          padding: EdgeInsets.only(right: 5,top: 0),
                          child: Image.asset(
                            items[index].img,
                            width: 60.0,
                            height: 60.0,
                          ),
                        ),
                      ),
                      Padding(
                          padding: const EdgeInsets.only(top: 0.0),
                          child: Container(
                            width: 200.0,
                            decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius: BorderRadius.only(
                                topLeft: const Radius.circular(50.0),
                                topRight: const Radius.circular(50.0),
                                bottomLeft: const Radius.circular(50.0),
                                bottomRight: const Radius.circular(50.0),
                              ),
                            ),
                            child: Wrap(
                              crossAxisAlignment: WrapCrossAlignment.center,
                              children:[
                                Padding(
                                  padding: const EdgeInsets.all(20.0),
                                  child: Center(
                                    child: Text(
                                      items[index].name,
                                      style: TextStyle(
                                          color: Colors.black,
                                          fontWeight: FontWeight.bold,
                                          fontSize: 25.0
                                      ),
                                    ),
                                  ),
                                )
                              ],
                            ),
                          )
                      ),
                    ],
                  ),
                ),
              );
            },),

【问题讨论】:

  • 我认为您可以使用条子通过 CustomScrollView 小部件来执行此操作。

标签: android flutter


【解决方案1】:

physics 添加为NeverScrollableScrollPhysics,这将停止ListView 滚动并采用SingleChildScrollView 滚动。

 ListView.builder(
                  physics: NeverScrollableScrollPhysics(),

【讨论】:

  • 这是一个错误解决方案,因为它会为给定的ListView 构建所有项目 - 例如,如果 itemCount 为 1000,那么将一次构建 1000 个项目跨度>
猜你喜欢
  • 2021-12-21
  • 2020-12-23
  • 2021-10-28
  • 1970-01-01
  • 2021-09-04
  • 2021-08-11
  • 2019-04-08
  • 2019-03-20
  • 2020-08-09
相关资源
最近更新 更多