Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class _BTMAppBarState extends State<BTMAppBar> {
- int navigationIndex = 0;
- GlobalKey globalKey = new GlobalKey(debugLabel: 'btm_app_bar');
- @override
- Widget build(BuildContext context) {
- return new Scaffold(
- bottomNavigationBar: new BottomNavigationBar(
- key: globalKey,
- items: [
- new BottomNavigationBarItem(
- title: new Text("Tap 1"), icon: new Icon(Icons.people)),
- new BottomNavigationBarItem(
- title: new Text("Tap 2"), icon: new Icon(Icons.build)),
- new BottomNavigationBarItem(
- title: new Text("Tap 3"), icon: new Icon(Icons.favorite)),
- ],
- onTap: (int index) {
- setState(() {
- navigationIndex = index;
- switch (navigationIndex) {
- case 0:
- print("navigate to screen 1");
- break;
- case 1:
- print("navigate to screen 2");
- break;
- case 2:
- print("navigate to screen 3");
- break;
- }
- });
- },
- ),
- body: new Center(
- child: new RaisedButton(onPressed: () {
- final BottomNavigationBar navigationBar = globalKey.currentWidget;
- navigationBar.onTap(2);
- }),
- ),
- );
- }
- }
Add Comment
Please, Sign In to add comment