Flutter:在 GridView 下方添加项目
Flutter: Add item below GridView
我需要在 Flutter 的 GridView 下面添加一个项目。它应该只有在一个人完全向下滚动网格时才可见。
项目应该是全角的,所以将它作为网格视图中的最后一个项目是不可能的。
我该怎么做?
首先创建一个列在第一个子项中添加您的网格代码,然后使用 Expanded() 显示您的最后一项。
见下面的代码。
Container(
child: Column(
children: <Widget>[
//your grid code
// grid code
Expanded(
child: Container(
child:Column(
//your last item.
)
),
),
],
)
)
您将需要 slivers 才能实现此目标。这里的想法是有很多列表并在开始滚动第二个之前完全滚动每个列表。
要使用 slivers,你需要一个 CustomScrollView
,它有一个名为 slivers
的 属性,在实践中,它的工作原理与 children
几乎相同,适用于多个子部件。
有多种银条小部件供您选择适合您需要的一种。如果需要 Grid,则必须使用 SliverGrid
。您可以通过 delegate
属性.
传递 Grid 子项
就我而言,没有 sliver 小部件将您限制为只有一个子部件 — 所有这些都是多个子部件 — 因此您提到的最后一个小部件必须在列表中(或您想要的其他任何东西) d 而不是)。
看来您需要这样的东西:
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
]),
),
],
),
);
我需要在 Flutter 的 GridView 下面添加一个项目。它应该只有在一个人完全向下滚动网格时才可见。
项目应该是全角的,所以将它作为网格视图中的最后一个项目是不可能的。
我该怎么做?
首先创建一个列在第一个子项中添加您的网格代码,然后使用 Expanded() 显示您的最后一项。
见下面的代码。
Container(
child: Column(
children: <Widget>[
//your grid code
// grid code
Expanded(
child: Container(
child:Column(
//your last item.
)
),
),
],
)
)
您将需要 slivers 才能实现此目标。这里的想法是有很多列表并在开始滚动第二个之前完全滚动每个列表。
要使用 slivers,你需要一个 CustomScrollView
,它有一个名为 slivers
的 属性,在实践中,它的工作原理与 children
几乎相同,适用于多个子部件。
有多种银条小部件供您选择适合您需要的一种。如果需要 Grid,则必须使用 SliverGrid
。您可以通过 delegate
属性.
就我而言,没有 sliver 小部件将您限制为只有一个子部件 — 所有这些都是多个子部件 — 因此您提到的最后一个小部件必须在列表中(或您想要的其他任何东西) d 而不是)。
看来您需要这样的东西:
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
]),
),
],
),
);