Last active
October 7, 2020 14:04
-
-
Save rickyngan/4469322fbdcf03be9265e75fc98fe7ef to your computer and use it in GitHub Desktop.
2020 Jun 13 HoC HK Flutter: 8_bottom_navigation_bar
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
import 'package:flutter/material.dart'; | |
void main() => runApp(App()); | |
class App extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'My Flutter App', | |
home: Home(), | |
); | |
} | |
} | |
class Home extends StatefulWidget { | |
@override | |
State<StatefulWidget> createState() { | |
return _HomeState(); | |
} | |
} | |
class _HomeState extends State<Home> { | |
int _currentIndex = 0; | |
final List<Widget> _children = [ | |
Container(color: Colors.white), | |
Container(color: Colors.deepOrange), | |
Container(color: Colors.green) | |
]; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('My Flutter App'), | |
), | |
body: _children[_currentIndex], | |
bottomNavigationBar: BottomNavigationBar( | |
onTap: onTabTapped, | |
currentIndex: _currentIndex, | |
items: [ | |
BottomNavigationBarItem( | |
icon: Icon(Icons.home), | |
label: Text('Home'), | |
), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.mail), | |
label: Text('Messages'), | |
), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.person), | |
label: Text('Profile') | |
) | |
], | |
), | |
); | |
} | |
void onTabTapped(int index) { | |
setState(() { | |
_currentIndex = index; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment