【问题标题】:How to create scrollable row in flutter如何在颤动中创建可滚动的行
【发布时间】:2020-09-05 20:17:02
【问题描述】:

我尝试在颤振中创建可滚动行

但在尝试了多种方法后,我面临高度固定或列表不滚动的问题

发布我尝试过的代码之一。

期待一种我可以连续滚动并且不需要为小部件固定高度的方式。

new Column(
    children: [
     new Container(
         height: 100.0,
         child: ListView(
            scrollDirection: Axis.horizontal,
              children: <Widget>[
                new Text("text 1"),
                new Text("text 2"),
                new Text("text 3"),
          ],
       ),
      ),
   ],
  ),

【问题讨论】:

    标签: flutter layout


    【解决方案1】:

    我已经回答了一些相关的问题,您不需要为小部件提供固定高度 并且您的小部件可以水平滚动

    你可以在这里查看

    https://stackoverflow.com/a/51937651/9236994

    提示:使用SingleChildScrollView 小部件

    SingleChildScrollView(
      scrollDirection: Axis.horizontal,
      child: Row(
       children: <Widget>[
         Text('hi'),
         Text('hi'),
         Text('hi'),
       ]
      )
    )
    

    【讨论】:

    • 可以联系一下,想学flutter,能帮我一下吗?
    • @Pranay 是的,你可以在linkedIN 上联系我,我也通过在线课程教授 FLUTTER,如果你有兴趣也可以加入。 linkedin.com/in/vicky-salunkhe
    【解决方案2】:

    这样的?

    new Column(
        children: [
         new Container(
             height: 100.0,
             child: Expanded(
                child: ListView.builder(
                  shrinkWrap: true,
                  itemBuilder: (context,int){
                    return Container(
                      child: Row(
                          children: <Widget>[
                            new Text("text 1"),
                            new Text("text 2"),
                            new Text("text 3"),
                      ],
                    );
                  },
                ),
              ),
            ],
          ),
          ),
       ],
      ),
    

    【讨论】:

      【解决方案3】:

      用 ListView 替换 Column 小部件。

      你可以看看 https://api.flutter.dev/flutter/widgets/ListView-class.html

      问候

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-23
        • 2018-11-18
        • 1970-01-01
        • 2021-04-30
        • 2021-11-29
        • 1970-01-01
        • 1970-01-01
        • 2022-07-15
        相关资源
        最近更新 更多