我在这里使用NestedScrollView
,并尝试将TabBar
放在bottom
函数内置的SliverAppBar
的{{1}}参数中。 headerSliverBuilder
可以正常工作,但是看起来TabBar
节省了SliverAppBar
的一些空间,使得标签栏看起来很奇怪,上面有很大的填充。任何想法如何删除此空间?预先感谢。
title
答案 0 :(得分:1)
您可以使用高度为0的PreferredSize
小部件来包装标签栏:
SliverOverlapAbsorber(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(
context),
sliver: SliverAppBar(
bottom: PreferredSize(
preferredSize: const Size.fromHeight(0),
child: TabBar(
controller: _controller,
labelColor: Colors.black,
indicatorColor: Colors.black,
unselectedLabelColor: Colors.grey,
tabs: _tabs
.map((String name) => Tab(text: name))
.toList()),
),
pinned: true,
floating: false,
expandedHeight: 500,
backgroundColor: Colors.white,
flexibleSpace: FlexibleSpaceBar(
collapseMode: CollapseMode.pin,
background: Container(
child: child: Center(child: Text("Today's lesson cancelled", style: GoogleFonts.montserrat(textStyle: TextStyle(color: Colors.white, fontSize:20, fontWeight: FontWeight.w500),)))
decoration: BoxDecoration(
color: Colors.white,
image: DecorationImage(
fit: BoxFit.cover,
image: DecorationImage(
image: AssetImage("assets/images/classroom.png")
)
),
)),
注意:我使用fit: BoxFit.cover
作为背景图片,这就是为什么标签栏没有白色背景的原因。
结果: