gpt4 book ai didi

flutter - 如何删除 SliverAppBar 中的空白空间?

转载 作者:行者123 更新时间:2023-12-04 13:12:49 33 4
gpt4 key购买 nike

我正在使用 NestedScrollView在这里并试图放一个 TabBarbottom SliverAppBar 的参数内置于 headerSliverBuilder功能。 TabBar工作正常,但它看起来像 SliverAppBar幸免于title一些空间使标签栏看起来很奇怪,上面有很大的填充。知道如何删除这个空间吗?提前致谢。
GIF

 @override
Widget build(BuildContext context) {
double screenWidth = MediaQuery.of(context).size.width;
double screenHeight = MediaQuery.of(context).size.height;
return Scaffold(
body: SafeArea(
child: NestedScrollView(
headerSliverBuilder: (context, value){
return[
SliverOverlapAbsorber(
handle:NestedScrollView.sliverOverlapAbsorberHandleFor(context),
sliver: SliverAppBar(
pinned: true,
floating: false,
expandedHeight: 500,
title: Text("Space that I don't want"),
centerTitle: true,
flexibleSpace: FlexibleSpaceBar(
collapseMode: CollapseMode.pin,
background: Container(
decoration: BoxDecoration(
color: Colors.white,
image: DecorationImage(
image: AssetImage("assets/images/classroom.png")
)
),
child: Center(child: Text("Today's lesson cancelled", style: GoogleFonts.montserrat(textStyle: TextStyle(color: Colors.white, fontSize:20, fontWeight: FontWeight.w500),)))
),
),
bottom: TabBar(
controller: _controller,
labelColor: Colors.black,
indicatorColor: Colors.black,
unselectedLabelColor: Colors.grey,
tabs: _tabs.map((String name) => Tab(text: name)).toList()
)
)
),
];
},
body: TabBarView(
controller: _controller,
children: (_tabs.map((String name){
return SafeArea(
child:Builder(
builder: (BuildContext context){
return CustomScrollView(
key: PageStorageKey<String>(name),
slivers: <Widget>[
SliverOverlapInjector(
handle:NestedScrollView.sliverOverlapAbsorberHandleFor(context),
),
SliverToBoxAdapter(
child: _buildLeaderBoardTab(screenWidth,screenHeight)
)
],
);
},
)
);
})).toList(),
)
)
)
);
}

最佳答案

你可以用 PreferredSize 包裹标签栏高度为 0 的小部件:

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对于背景图像,这就是标签栏没有白色背景的原因。
结果:
res

关于flutter - 如何删除 SliverAppBar 中的空白空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63309188/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com