Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MainPage extends StatefulWidget {
- @override
- State createState() {
- return new MainPageState();
- }
- }
- class MainPageState extends State<MainPage> {
- int _currentIndex = 0;
- List<int> _history = [0];
- @override
- Widget build(BuildContext context) {
- return new Scaffold(
- appBar: new AppBar(
- title: new Text('Bottom Nav Back'),
- ),
- body: new Center(
- child: new Text('Page $_currentIndex'),
- ),
- bottomNavigationBar: new BottomNavigationBar(
- currentIndex: _currentIndex,
- items: <BottomNavigationBarItem>[
- new BottomNavigationBarItem(
- icon: new Icon(Icons.touch_app),
- title: new Text('keypad'),
- ),
- new BottomNavigationBarItem(
- icon: new Icon(Icons.assessment),
- title: new Text('chart'),
- ),
- new BottomNavigationBarItem(
- icon: new Icon(Icons.cloud),
- title: new Text('weather'),
- ),
- ],
- onTap: (int index) {
- _history.add(index);
- setState(() => _currentIndex = index);
- Navigator.push(context, new BottomNavigationRoute()).then((x) {
- _history.removeLast();
- setState(() => _currentIndex = _history.last);
- });
- },
- ),
- );
- }
- }
- class BottomNavigationRoute extends LocalHistoryRoute<void> {}
Add Comment
Please, Sign In to add comment