【问题标题】:How do I convert a listView to a GridView flutter?如何将 listView 转换为 GridView 颤振?
【发布时间】:2020-04-28 19:09:17
【问题描述】:

我有一个水平格式的可滚动列表视图,我想将其转换为具有相同元素的网格视图。

Container(
  height: MediaQuery.of(context).size.height / 4,
  child: ListView.builder(
    scrollDirection: Axis.horizontal,
    itemCount: homeList.length,
    itemBuilder: (ctx, i) {
      return GestureDetector(
        onTap: () {
          if (i == 0) {            
            _interstitialAd.show();
          } else if (i == 1) {

          } else if (i == 2) {
            sendInvite();
          }
        },
      );
    },
  ),
)

这是列表视图的样子:

这就是我想要的样子:

【问题讨论】:

  • 你希望它也可以水平滚动吗?
  • 没有,不需要。仅垂直。

标签: user-interface flutter gridview dart


【解决方案1】:

Flutter 与 ListView.builder 等效于 GridView。 您只需要告诉它您想要的列数/行数(取决于方向)。

GridView.builder(
          itemCount: homeList.length,
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount:2),
          itemBuilder: (BuildContext context, int index) {
             return GestureDetector(
                 onTap: () {
                  if (i == 0) {
                       _interstitialAd.show();
                  } else if (i == 1) {

                  } else if (i == 2) {
                      sendInvite();
                  });
          },
    )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-16
    • 1970-01-01
    • 2020-10-02
    • 2020-09-03
    • 2021-11-08
    • 2022-01-18
    • 2020-02-08
    • 1970-01-01
    相关资源
    最近更新 更多