Flutter 当SliverAppBar为最小高度时隐藏底部导航栏
当我的滑动应用条必须达到最小高度时,我正在尝试更改自定义底部导航条的位置 -从这里开始实施 这是我的密码Flutter 当SliverAppBar为最小高度时隐藏底部导航栏,flutter,Flutter,当我的滑动应用条必须达到最小高度时,我正在尝试更改自定义底部导航条的位置 -从这里开始实施 这是我的密码 class _MainPageState extends State<MainPage> { int _currentIndex = 0; bool _headerOpen = true; @override void initState() { super.initState(); } @override Widget build(Bui
class _MainPageState extends State<MainPage> {
int _currentIndex = 0;
bool _headerOpen = true;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
expandedHeight: 250,
pinned: true,
flexibleSpace: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
if (constraints.biggest.height -
MediaQuery.of(context).padding.top ==
kToolbarHeight) {
_headerOpen = false;
} else {
_headerOpen = true;
}
return FlexibleSpaceBar(
title: Text(_headerOpen.toString()),
);
},
),
)
];
},
body: Stack(
children: [
ListView.builder(
itemCount: 100,
itemBuilder: (context, index) {
return Text("Index is " + index.toString());
},
),
Positioned(
left: 0,
right: 0,
bottom: _headerOpen ? 28 : -500,
child: SafeArea(
bottom: true,
child: CustomNavigationBar(
// implement of my bottom bar
),
),
)
],
),
),
);
}
}
class\u MainPageState扩展状态{
int _currentIndex=0;
bool_headerOpen=true;
@凌驾
void initState(){
super.initState();
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:嵌套滚动视图(
headerSliverBuilder:(BuildContext上下文,boolInnerBoxIsCrolled){
返回[
滑杆(
扩展高度:250,
对,,
flexibleSpace:LayoutBuilder(
生成器:(BuildContext上下文,BoxConstraints){
if(约束条件、最大值、高度)-
MediaQuery.of(context.padding.top)==
KToolbar(高度){
_headerOpen=假;
}否则{
_headerOpen=true;
}
返回柔性空格键(
标题:文本(_headerOpen.toString()),
);
},
),
)
];
},
主体:堆栈(
儿童:[
ListView.builder(
物品计数:100,
itemBuilder:(上下文,索引){
返回文本(“索引为”+Index.toString());
},
),
定位(
左:0,,
右:0,,
底部:_headerOpen?28:-500,
儿童:安全区(
底部:是的,
子项:CustomNavigationBar(
//实现我的底部酒吧
),
),
)
],
),
),
);
}
}
我想这是因为SliverAppBat更改大小时主小部件构建没有更新,但我不知道该怎么做。我有点困惑,你想隐藏它还是怎么做?因为你的标题说你想隐藏它 如果你想隐藏它,你可以使用widget。然后将您的
位置
包装到此位置
Visibility(
visible: _headerOpen,
child: Positioned(
left: 0,
right: 0,
child: SafeArea(
bottom: true,
child: CustomNavigationBar(
// implement of my bottom bar
),
),
),
);