I am currently working on a application which has both appbar and bottom navbar. I wanted the appbar and bottom navbar hide while the user scroll. I have two screens
- Navbar screen : Here the code for bottom navbar and appbar is written which consists where body is the UI shown to the user.
- ListView Screen: This is the UI which consists a list of data.
I wanted the output like this:
NavBar :
class MyNavBarr extends StatefulWidget {
const MyNavBarr({super.key});
@override
State<MyNavBarr> createState() => _MyNavBarrState();
}
class _MyNavBarrState extends State<MyNavBarr> {
int _selectedIndex = 0;
static const List<Widget> _widgetOptions = <Widget>[
LiistView(),
LiistView(),
LiistView(),
LiistView(),
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("AppBar"),
centerTitle: true,
),
body: _widgetOptions.elementAt(_selectedIndex),
bottomNavigationBar: SizedBox(
height: 65.0,
child: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(IconlyLight.image),
label: '',
),
BottomNavigationBarItem(
icon: Icon(IconlyLight.video),
label: '',
),
BottomNavigationBarItem(
icon: Icon(Icons.library_music_outlined),
label: '',
),
BottomNavigationBarItem(
icon: Icon(IconlyLight.profile),
label: '',
),
],
currentIndex: _selectedIndex,
showSelectedLabels: true,
showUnselectedLabels: false,
selectedFontSize: 0.0,
type: BottomNavigationBarType.fixed,
onTap: _onItemTapped,
),
),
);
}
}
ListView :
class LiistView extends StatefulWidget {
const LiistView({super.key});
@override
State<LiistView> createState() => _LiistViewState();
}
class _LiistViewState extends State<LiistView> {
final controller = ScrollController();
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
itemCount: 80,
itemBuilder: (context, index){
return const ListTile(
title: Text("Abcd"),
);
},
),
);
}
}