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

时间:2020-08-07 21:10:42

标签: flutter sliverappbar

我在这里使用NestedScrollView,并尝试将TabBar放在bottom函数内置的SliverAppBar的{​​{1}}参数中。 headerSliverBuilder可以正常工作,但是看起来TabBar节省了SliverAppBar的一些空间,使得标签栏看起来很奇怪,上面有很大的填充。任何想法如何删除此空间?预先感谢。

GIF

title

1 个答案:

答案 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作为背景图片,这就是为什么标签栏没有白色背景的原因。

结果:

res