我正在尝试使用标签创建隐藏的sliverappbar。当我开始向下滚动时,它必须隐藏;当我开始向上滚动时,它必须显示。现在,当我向下滚动时,appbar隐藏,但在向上滚动开始时未显示,但在滚动结束时显示。我也需要保存tabbarview页面位置,但是当我尝试这样做时,appbar不再隐藏了。
class ConferentionsPage extends StatefulWidget{
final void Function() openMenu;
ConferentionsPage({Key key, this.openMenu}): super(key: key);
@override
State<StatefulWidget> createState() => ConferentionsPageState();
}
class ConferentionsPageState extends State<ConferentionsPage>
with SingleTickerProviderStateMixin {
TabController _tabController;
ScrollController _scrollController;
double listViewOffset = 0.0;
_buildSliverAppBar(BuildContext context, bool innerIsScrolled){
return SliverAppBar(
leading: IconButton(
icon: Image.asset('assets/icons/menu.png', width: 24, height: 24,),
onPressed: widget.openMenu
),
title: Text(CONFERENTIONS_TITLE),
centerTitle: true,
elevation: .6,
actions: <Widget>[
IconButton(
icon: Image.asset('assets/icons/user.png', width: 24.0, height: 24.0,),
onPressed: (){
},
)
],
pinned: true,
floating: true,
snap: true,
forceElevated: innerIsScrolled,
bottom: TabBar(
controller: _tabController,
tabs: <Widget>[
Tab(text: 'Прошедшие',),
Tab(text: 'Ближайшие',)
],
),
);
}
@override
void initState() {
super.initState();
_tabController = TabController(length: 2, vsync: this);
_scrollController = ScrollController(initialScrollOffset: 0, keepScrollOffset: true);
}
@override
Widget build(BuildContext context) {
return NestedScrollView(
controller: _scrollController,
headerSliverBuilder: (BuildContext context, bool innerIsScrolled){
return <Widget>[
_buildSliverAppBar(context, innerIsScrolled)
];
},
body: TabBarView(
controller: _tabController,
children: <Widget>[
Tab1(),
Tab1()
],
),
);
}
}