Skip to content

Instantly share code, notes, and snippets.

@GursheeshSingh
Created August 7, 2020 21:02
Show Gist options
  • Save GursheeshSingh/71f4b114c27556a25c4cdb1803d1413d to your computer and use it in GitHub Desktop.
Save GursheeshSingh/71f4b114c27556a25c4cdb1803d1413d to your computer and use it in GitHub Desktop.
class BottomBarScreen extends StatefulWidget {
@override
_BottomBarScreenState createState() => _BottomBarScreenState();
}
class _BottomBarScreenState extends State<BottomBarScreen> {
int _currentIndex = 0;
final List<Widget> _children = [
PlaceholderWidget(Colors.white),
PlaceholderWidget(Colors.deepOrange),
PlaceholderWidget(Colors.green)
];
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
if (_currentIndex == 0) {
return true;
}
setState(() {
_currentIndex = 0;
});
return false;
},
child: Scaffold(
appBar: AppBar(
title: Text('Flutter Bottem Navi '),
),
body: _children[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
onTap: onTabTapped,
currentIndex: _currentIndex,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
title: Text('Search'),
),
BottomNavigationBarItem(
icon: Icon(Icons.person), title: Text('Profile'))
],
),
),
);
}
void onTabTapped(int index) {
setState(() {
_currentIndex = index;
});
}
}
class PlaceholderWidget extends StatelessWidget {
final Color color;
PlaceholderWidget(this.color);
@override
Widget build(BuildContext context) {
return Container(
color: color,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment