Flutter 颤振-拆下空间调整杆和滑动调整杆
我想实现一个底部带有固定TabBar的float AppBar。以下是测试代码():Flutter 颤振-拆下空间调整杆和滑动调整杆,flutter,flutter-sliverappbar,Flutter,Flutter Sliverappbar,我想实现一个底部带有固定TabBar的float AppBar。以下是测试代码(): 小部件构建(构建上下文){ 返回脚手架( 正文:嵌套滚动视图( 浮头肝脏:是的, headerSliverBuilder:(BuildContext上下文,boolInnerBoxIsCrolled){ 返回[ 滑杆( 背景颜色:Colors.yellow, 标题:正文( “WhatsApp型条子appbar”, ), 标题:对, 对,, 浮动:是的, 底部:首选尺寸( preferredSize:Size.f
小部件构建(构建上下文){
返回脚手架(
正文:嵌套滚动视图(
浮头肝脏:是的,
headerSliverBuilder:(BuildContext上下文,boolInnerBoxIsCrolled){
返回[
滑杆(
背景颜色:Colors.yellow,
标题:正文(
“WhatsApp型条子appbar”,
),
标题:对,
对,,
浮动:是的,
底部:首选尺寸(
preferredSize:Size.fromHeight(kToolbarHeight),
子:容器(
颜色:颜色。橙色,
对齐:alignment.topLeft,
孩子:TabBar(
isScrollable:是的,
指示颜色:颜色。白色,
indicatorSize:TabBarIndicatorSize.label,
控制器:\ tab控制器,
标签填充:仅限边缘集(
顶部:13,底部:13,左侧:16,右侧:16),
选项卡:[
正文(
“表A”,
),
正文(
“选项卡B”,
),
]),
),
),
),
];
},
正文:选项卡视图(
控制器:\ tab控制器,
儿童:[
TabA(),
康斯特中心(
子项:文本('显示选项卡2',
样式:TextStyle(fontSize:16,fontWeight:fontWeight.bold)),
),
],
),
),
);
}
我发现向下滚动时,选项卡栏上会有一个顶部填充。有没有办法去掉那个空间?我已经设置了滑动应用条的工具栏高度,但即使我降低了高度,该空间仍将保持不变
向上滚动(显示应用程序栏):
向下滚动(隐藏appbar,顶部的黄色不隐藏):只需设置属性
锁定:false
看
钉住→ 布尔
应用程序栏是否应在滚动视图开始时保持可见。[...]
决赛
同时从底部删除tabBar:并将其添加到tabbarview上方的列中谢谢您的帮助 最后,我还有另一个可以考虑的解决方案。我在这里发布供其他人参考
Widget build(BuildContext context) {
return Scaffold(
body: NestedScrollView(
floatHeaderSlivers: true,
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
backgroundColor: Colors.yellow,
title: Text(
"WhatsApp type sliver appbar",
),
elevation: 0.0,
forceElevated: false,
pinned: false,
floating: true,
primary: false,
centerTitle: false,
titleSpacing: NavigationToolbar.kMiddleSpacing,
automaticallyImplyLeading: false,
),
SliverAppBar(
backgroundColor: Colors.orange,
pinned: true,
primary: false,
centerTitle: false,
titleSpacing: 0,
toolbarHeight: 48,
automaticallyImplyLeading: false,
forceElevated: true,
title: Align(
alignment: Alignment.topLeft,
child: TabBar(
isScrollable: true,
indicatorColor: Colors.white,
indicatorSize: TabBarIndicatorSize.label,
controller: _tabController,
labelPadding: EdgeInsets.only(
top: 13, bottom: 13, left: 16, right: 16),
tabs: [
Text(
"TAB A",
),
Text(
"TAB B",
),
]),
),
),
];
},
body: TabBarView(
controller: _tabController,
children: [
TabA(),
const Center(
child: Text('Display Tab 2',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
),
],
),
),
);
}
小部件构建(构建上下文){
返回脚手架(
正文:嵌套滚动视图(
浮头肝脏:是的,
headerSliverBuilder:(BuildContext上下文,boolInnerBoxIsCrolled){
返回[
滑杆(
背景颜色:Colors.yellow,
标题:正文(
“WhatsApp型条子appbar”,
),
标高:0.0,
错误:错,,
错,,
浮动:是的,
主要:错误,
标题:错误,
标题间距:NavigationToolbar.kMiddleSpacing,
自动嵌入:false,
),
滑杆(
背景颜色:Colors.orange,
对,,
主要:错误,
标题:错误,
标题间距:0,
身高:48,
自动嵌入:false,
对,,
标题:对齐(
对齐:alignment.topLeft,
孩子:TabBar(
isScrollable:是的,
指示颜色:颜色。白色,
indicatorSize:TabBarIndicatorSize.label,
控制器:\ tab控制器,
标签填充:仅限边缘集(
顶部:13,底部:13,左侧:16,右侧:16),
选项卡:[
正文(
“表A”,
),
正文(
“选项卡B”,
),
]),
),
),
];
},
正文:选项卡视图(
控制器:\ tab控制器,
儿童:[
TabA(),
康斯特中心(
子项:文本('显示选项卡2',
样式:TextStyle(fontSize:16,fontWeight:fontWeight.bold)),
),
],
),
),
);
}
基本上,我所做的是分开的2个滑动条,一个不是固定和浮动的;另一个是别针。这会使上appbar在向下滚动时消失,在向上滚动时显示,而tabbar会一直固定在那里。您是否尝试在脚手架中使用appbar属性?您是否尝试添加属性
isDense:true
?@KabirouAgouda是的,我尝试过,并且有相同的结果result@AntoninGAVREL很抱歉我看不出有一个isDense参数SliverAppBar@AntoninGAVRELisDense属性仅位于DropDownButton或InputDecoration中请随时向上投票我的答案;)
Widget build(BuildContext context) {
return Scaffold(
body: NestedScrollView(
floatHeaderSlivers: true,
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
backgroundColor: Colors.yellow,
title: Text(
"WhatsApp type sliver appbar",
),
elevation: 0.0,
forceElevated: false,
pinned: false,
floating: true,
primary: false,
centerTitle: false,
titleSpacing: NavigationToolbar.kMiddleSpacing,
automaticallyImplyLeading: false,
),
SliverAppBar(
backgroundColor: Colors.orange,
pinned: true,
primary: false,
centerTitle: false,
titleSpacing: 0,
toolbarHeight: 48,
automaticallyImplyLeading: false,
forceElevated: true,
title: Align(
alignment: Alignment.topLeft,
child: TabBar(
isScrollable: true,
indicatorColor: Colors.white,
indicatorSize: TabBarIndicatorSize.label,
controller: _tabController,
labelPadding: EdgeInsets.only(
top: 13, bottom: 13, left: 16, right: 16),
tabs: [
Text(
"TAB A",
),
Text(
"TAB B",
),
]),
),
),
];
},
body: TabBarView(
controller: _tabController,
children: [
TabA(),
const Center(
child: Text('Display Tab 2',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
),
],
),
),
);
}