颤振:在GridView下添加项目

颤振:在GridView下添加项目,gridview,layout,flutter,Gridview,Layout,Flutter,我需要在Flatter中的GridView下面添加一个项目。只有当一个人完全沿着网格向下滚动时,它才可见 该项应该是全宽的,因此将其作为gridview中的最后一项是不可能的 如何执行此操作?首先创建一列,在第一个子项中添加网格代码,然后使用Expanded()显示最后一项 请参阅下面的代码 Container( child: Column( children: <Widget>[ //your grid code // grid code

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

该项应该是全宽的,因此将其作为gridview中的最后一项是不可能的


如何执行此操作?

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

请参阅下面的代码

Container(
  child: Column(
    children: <Widget>[
      //your grid code
      // grid code
      Expanded(
        child: Container(
          child:Column(
            //your last item.
          )
        ),
      ),
    ],
  )
)
容器(
子:列(
儿童:[
//你的网格代码
//网格代码
扩大(
子:容器(
子:列(
//你的最后一项。
)
),
),
],
)
)
您需要实现这一点。这里的想法是有很多列表,在开始滚动第二个列表之前,完全滚动每个列表

要使用slivers,您需要一个
CustomScrollView
,它有一个名为
slivers
的属性,在实践中,它的工作原理与
子控件的工作原理几乎相同

有各种各样的小部件供您选择适合您需要的小部件。如果需要网格,则必须使用
SliverGrid
。您可以通过
委托
属性传递网格子项

就我而言,没有一个狭长的小部件将您限制为只有一个子小部件-所有这些小部件都是多个子小部件-因此您提到的最后一个小部件必须位于列表中(或者您希望的任何其他小部件)

看起来你需要这样的东西:

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
        ]),
      ),
    ],
  ),
);