Created
August 7, 2020 21:02
-
-
Save GursheeshSingh/71f4b114c27556a25c4cdb1803d1413d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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