gpt4 book ai didi

flutter - 如何在 SliverAppBar 中仅显示选项卡 View

转载 作者:IT王子 更新时间:2023-10-29 07:04:35 30 4
gpt4 key购买 nike

我基本上希望在我的页面中间有一个 TabView 导航。为此,我在 NestedScrollView 中使用了 SliverAppBar。我的 SliverAppBar 仅由我的 TabView 组成,我将 TabView 包裹在 SliverAppBar 中,以便使用 pinned: true 属性。

return Scaffold(
appBar: AppBar(
title: Text('Title'),
),
body: NestedScrollView(

headerSliverBuilder: (BuildContext context, bool boxIsScrolled) {
return <Widget>[
SliverToBoxAdapter(
child: Container(
height: 500,
color: Colors.red,
)),

SliverAppBar(
pinned: true,
bottom: TabBar(
tabs: <Widget>[
Tab(
text: "Home",
icon: Icon(Icons.home),
),
Tab(
text: "Example page",
icon: Icon(Icons.help),
)
],
controller: _tabController,
)),

];
},
body: TabBarView(
children: <Widget>[
PageExample(),
PageExample(),
],
controller: _tabController,
),
),
);

它确实有效,我的问题是我想隐藏/删除包裹我的 TabBar 的这个 SliverAppBar:

enter image description here

最佳答案

我需要将 expandedHeight 设置为 0:

返回脚手架( 应用栏:应用栏( title: 文本('标题'), ), 正文:嵌套 ScrollView (

    headerSliverBuilder: (BuildContext context, bool boxIsScrolled) {
return <Widget>[
SliverToBoxAdapter(
child: Container(
height: 500,
color: Colors.red,
)),

SliverAppBar(
expandedHeight: 0,
pinned: true,
bottom: TabBar(
tabs: <Widget>[
Tab(
text: "Home",
icon: Icon(Icons.home),
),
Tab(
text: "Example page",
icon: Icon(Icons.help),
)
],
controller: _tabController,
)),

];
},
body: TabBarView(
children: <Widget>[
PageExample(),
PageExample(),
],
controller: _tabController,
),
),
);

关于flutter - 如何在 SliverAppBar 中仅显示选项卡 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54526161/

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