Guest User

Untitled

a guest
May 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. class MainPage extends StatefulWidget {
  2. @override
  3. State createState() {
  4. return new MainPageState();
  5. }
  6. }
  7.  
  8. class MainPageState extends State<MainPage> {
  9. int _currentIndex = 0;
  10. List<int> _history = [0];
  11.  
  12. @override
  13. Widget build(BuildContext context) {
  14. return new Scaffold(
  15. appBar: new AppBar(
  16. title: new Text('Bottom Nav Back'),
  17. ),
  18. body: new Center(
  19. child: new Text('Page $_currentIndex'),
  20. ),
  21. bottomNavigationBar: new BottomNavigationBar(
  22. currentIndex: _currentIndex,
  23. items: <BottomNavigationBarItem>[
  24. new BottomNavigationBarItem(
  25. icon: new Icon(Icons.touch_app),
  26. title: new Text('keypad'),
  27. ),
  28. new BottomNavigationBarItem(
  29. icon: new Icon(Icons.assessment),
  30. title: new Text('chart'),
  31. ),
  32. new BottomNavigationBarItem(
  33. icon: new Icon(Icons.cloud),
  34. title: new Text('weather'),
  35. ),
  36. ],
  37. onTap: (int index) {
  38. _history.add(index);
  39. setState(() => _currentIndex = index);
  40. Navigator.push(context, new BottomNavigationRoute()).then((x) {
  41. _history.removeLast();
  42. setState(() => _currentIndex = _history.last);
  43. });
  44. },
  45. ),
  46. );
  47. }
  48. }
  49.  
  50. class BottomNavigationRoute extends LocalHistoryRoute<void> {}
Add Comment
Please, Sign In to add comment