Guest User

Untitled

a guest
Jun 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. class _BTMAppBarState extends State<BTMAppBar> {
  2. int navigationIndex = 0;
  3. GlobalKey globalKey = new GlobalKey(debugLabel: 'btm_app_bar');
  4.  
  5. @override
  6. Widget build(BuildContext context) {
  7. return new Scaffold(
  8. bottomNavigationBar: new BottomNavigationBar(
  9. key: globalKey,
  10. items: [
  11. new BottomNavigationBarItem(
  12. title: new Text("Tap 1"), icon: new Icon(Icons.people)),
  13. new BottomNavigationBarItem(
  14. title: new Text("Tap 2"), icon: new Icon(Icons.build)),
  15. new BottomNavigationBarItem(
  16. title: new Text("Tap 3"), icon: new Icon(Icons.favorite)),
  17. ],
  18. onTap: (int index) {
  19. setState(() {
  20. navigationIndex = index;
  21. switch (navigationIndex) {
  22. case 0:
  23. print("navigate to screen 1");
  24. break;
  25. case 1:
  26. print("navigate to screen 2");
  27. break;
  28. case 2:
  29. print("navigate to screen 3");
  30. break;
  31. }
  32. });
  33. },
  34. ),
  35. body: new Center(
  36. child: new RaisedButton(onPressed: () {
  37. final BottomNavigationBar navigationBar = globalKey.currentWidget;
  38. navigationBar.onTap(2);
  39. }),
  40. ),
  41. );
  42. }
  43. }
Add Comment
Please, Sign In to add comment