Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide Appbar on Scroll Flutter?

Sample Image

Consider this image. As you can see it has an appbar and the appbar has Tabbed buttons. Am trying to animate the appbar so that it hides on scrollup and leaves only the Tab Buttons showing and on scrollup the appbar apears. Please help me out. Sorry for bad english and not American neither am I English

like image 881
Favor Avatar asked Aug 21 '18 12:08

Favor


People also ask

How do I hide the top AppBar flutter?

As We Need To Hide AppBar We Need To Use NestedScrollView Taking headerSliverBuilder That Detect Scrolling And returning SliverAppBar. Now SliverAppBar Will Auto Hide When users Scroll Down And reappear When User Scroll To The Top. SliverAppBar Taking Height, Title, And Leading That Show An Icon.


2 Answers

If I understood you correctly, following code should make the app bar hide on scroll while TabBar remains visible:

Null safe code:

class _SomePageState extends State<SomePage> with SingleTickerProviderStateMixin {   late final TabController _tabController;    @override   void initState() {     super.initState();     _tabController = TabController(length: 2, vsync: this);   }    @override   Widget build(BuildContext context) {     return Scaffold(       body: NestedScrollView(         headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {           return <Widget>[             SliverAppBar(               title: Text('Weight Tracker'),               pinned: true,               floating: true,               forceElevated: innerBoxIsScrolled,               bottom: TabBar(                 tabs: <Tab>[                   Tab(text: 'STATISTICS'),                   Tab(text: 'HISTORY'),                 ],                 controller: _tabController,               ),             ),           ];         },         body: TabBarView(           controller: _tabController,           children: <Widget>[             StatisticsPage(),             HistoryPage(),           ],         ),       ),     );   } } 

enter image description here

Example coming from this post.

like image 92
Marcin Szałek Avatar answered Oct 04 '22 23:10

Marcin Szałek


Using DefaultTabController

DefaultTabController(       length: 2,       child: new Scaffold(         body: new NestedScrollView(           headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {             return <Widget>[               new SliverAppBar(                 title: Text("Application"),                 floating: true,                 pinned: true,                 snap: true,                 bottom: new TabBar(                   tabs: <Tab>[                     new Tab(text: "T"),                     new Tab(text: "B"),                   ], // <-- total of 2 tabs                 ),               ),             ];           },           body: new TabBarView(             children: <Widget>[               Center(                   child: Text(                 'T Tab',                 style: TextStyle(fontSize: 30),               )),               Center(                   child: Text(                 'B Tab',                 style: TextStyle(fontSize: 30),               )),             ],           ),         ),       ),     ); 

Output:

enter image description here

like image 37
Jitesh Mohite Avatar answered Oct 04 '22 23:10

Jitesh Mohite