Flutter:在GridView下面添加项目

时间:2019-05-01 19:00:36

标签: gridview layout flutter

我需要在Flutter中的GridView下面添加一个项目。只有当一个人完全向下滚动网格时,它才应该可见。

该项目应为全角,因此将其作为表格视图中的最后一个项目是不可能的。

我该怎么做?

2 个答案:

答案 0 :(得分:1)

您将需要slivers才能实现。这里的想法是拥有很多列表,并在开始滚动第二个列表之前完全滚动每个列表。

要使用薄片,您需要一个CustomScrollView,它具有一个称为slivers的属性,实际上,它与children的作用与多个子小部件的作用几乎相同。

有许多条状小部件供您选择适合您需求的小部件。如果需要网格,则必须使用SliverGrid。您可以通过delegate属性传递Grid子代。

就我而言,没有一个条状小部件将您限制为一个孩子-所有这些都是多个子小部件-因此,您提到的最后一个小部件必须位于列表中(或者您想要的其他任何内容) )。

好像您需要这样的东西:

Container(
  child: CustomScrollView(
    slivers: [
      // This one is scrolled first
      SliverGrid(
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
        delegate: SliverChildListDelegate([
          // Place your children here
        ]),
      ),
      // Then this one becomes visible and start scrolling as well
      SliverList(
        delegate: SliverChildListDelegate([
          // Place that last widget here
        ]),
      ),
    ],
  ),
);

答案 1 :(得分:-1)

首先创建一列,然后在“第一个子项”中添加网格代码,然后使用Expanded()显示最后一个项目。

请参见下面的代码。

Container(
  child: Column(
    children: <Widget>[
      //your grid code
      // grid code
      Expanded(
        child: Container(
          child:Column(
            //your last item.
          )
        ),
      ),
    ],
  )
)
相关问题