Skip to content

Instantly share code, notes, and snippets.

@omofolarin
Forked from NeatSnippets/home.dart
Created November 21, 2022 20:07
Show Gist options
  • Select an option

  • Save omofolarin/a72a31de682ea910bace8a8b7b3a6f91 to your computer and use it in GitHub Desktop.

Select an option

Save omofolarin/a72a31de682ea910bace8a8b7b3a6f91 to your computer and use it in GitHub Desktop.
How to hide bottom navigation bar when scrolling in Flutter
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class Home extends StatefulWidget {
Home({Key key}) : super(key: key);
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
ScrollController _scrollController;
@override
void initState() {
super.initState();
_scrollController = ScrollController();
}
@override
void dispose() {
_scrollController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Hide Bottom Navigation Bar'),
),
body: Container(
width: double.infinity,
child: ListView.builder(
controller: _scrollController,
itemBuilder: (context, index) {
return ListTile(
title: Text('Google $index'),
onTap: () {},
);
},
),
),
bottomNavigationBar: AnimatedBuilder(
animation: _scrollController,
builder: (context, child) {
return AnimatedContainer(
duration: Duration(milliseconds: 300),
height: _scrollController.position.userScrollDirection == ScrollDirection.reverse ? 0: 100,
child: child,
);
},
child: BottomNavigationBar(
backgroundColor: Colors.amber[200],
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
BottomNavigationBarItem(
icon: Icon(Icons.child_friendly),
title: Text('Child'),
),
],
),
),
);
}
}
//When you run the app in release mode, you will get a better performance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment