我想要的是,当我向上滚动 GridView 时,Carousel 向上滚动并且选项卡控制器保持在顶部固定。所有这些都应该在一个卷轴中完成。我之前使用自定义滚动和条子 GridView 完成了此操作,但我不知道如何在自定义滚动视图中添加默认选项卡控制器并使其保持固定在顶部。
谢谢你的帮助 :)
我想要的是,当我向上滚动 GridView 时,Carousel 向上滚动并且选项卡控制器保持在顶部固定。所有这些都应该在一个卷轴中完成。我之前使用自定义滚动和条子 GridView 完成了此操作,但我不知道如何在自定义滚动视图中添加默认选项卡控制器并使其保持固定在顶部。
谢谢你的帮助 :)
我试过下面的代码希望它能解决你的问题....
您也可以在 DartPad NestedScrollView中使用此代码
NestedScrollView(
physics: ClampingScrollPhysics(),
headerSliverBuilder: (context, value) {
return [
SliverToBoxAdapter(
/// _buildCarousel() in your case....
child: Container(
height: 200,
child: Center(
child: Text("Your Carousel will be here"),
)
),
),
SliverToBoxAdapter(
child: TabBar(
labelColor: Colors.blue,
unselectedLabelColor: Colors.black,
controller: tb,
tabs: <Widget>[
Tab(child: Text("tab1"),),
Tab(child: Text("tab2"),)
],
)
),
];
},
body: TabBarView(
controller: tb,
children: <Widget>[
GridView.count(
physics: NeverScrollableScrollPhysics(),
crossAxisCount: 3,
children: List.generate(10,
(index) => Icon(Icons.grid_off)
).toList()
),
GridView.count(
physics: NeverScrollableScrollPhysics(),
crossAxisCount: 3,
children: List.generate(5,
(index) => Icon(Icons.grid_on)
).toList()
),
],
),
)
查看此 DartPad 以了解如何运行 ex。PinnedAppBar_SliverAppBar_NestedScrollView
NestedScrollView(
controller: ScrollController(),
physics: ClampingScrollPhysics(),
headerSliverBuilder: (context, value) {
return [
SliverAppBar(
pinned: true,
backgroundColor: Colors.white,
flexibleSpace: FlexibleSpaceBar(
background:
/// _buildCarousel() in your case....
Container(
height: 200,
child: Center(
child: Text("Your Carousel will be here"),
)
),
),
expandedHeight: 250.0, /// your Carousel + Tabbar height(50)
floating: true,
bottom: TabBar(
labelColor: Colors.blue,
unselectedLabelColor: Colors.black,
controller: tb,
tabs: <Widget>[
Tab(child: Text("tab1"),),
Tab(child: Text("tab2"),)
],
),
),
];
},
body: TabBarView(
controller: tb,
children: <Widget>[
GridView.count(
crossAxisCount: 3,
children: List.generate(10,
(index) => Icon(Icons.grid_off)
).toList()
),
GridView.count(
crossAxisCount: 3,
children: List.generate(5,
(index) => Icon(Icons.grid_on)
).toList()
),
],
),
)