最近,我弄清楚了如何在SliverAppBar中实现选项卡。但是现在我有一个问题,我需要在TabBarView中将SliverStaggeredGrid作为一个孩子。
这是到目前为止的我的代码(简体):
Widget build(BuildContext context) {
return FutureBuilder(
future: widget._future,
builder:
((context, AsyncSnapshot<List<DocumentSnapshot>> snapshotPosts) {
return CustomScrollView(
slivers: <Widget>[
SliverAppBar(
bottom: TabBar(
tabs: [
Tab(text: 'Tab 1'),
Tab(text: 'Tab 2'),
],
controller: controller,
),
title: Text("Test")),
SliverFillRemaining(
child: TabBarView(
controller: controller,
children: <Widget>[
buildGrid(snapshotPosts),
Center(child: Text("Tab two")),
],
),
),
],
);
}));
}
buildGrid(AsyncSnapshot<List<DocumentSnapshot>> snapshot) {
return SliverStaggeredGrid.countBuilder(
crossAxisCount: 3,
itemCount: snapshot.data.length,
itemBuilder: ((BuildContext context, int index) {
return ListTile(
title: Text(snapshot.data[index].toString()),
);
}
// Your desired amount of children he
),
staggeredTileBuilder: (int index) => new StaggeredTile.fit(1),
mainAxisSpacing: 6.0,
crossAxisSpacing: 6.0,
);
}
如何将buildGrid作为TabBarView的子级实现?
有什么想法吗?谢谢!