Navigate using bottom app bar tabs flutter. You can use a BottomNavigationBarItem instead of creating buttons and use the ontap of the bottomNavigationBar.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
class _MyHomePageState extends State<MyHomePage> { int _index = 0; final List<Widget> _children = [ Center(child: Text("First Page"),), Center(child: Text("Second Page"),), Center(child: Text("Third Page"),) ]; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Bottom Navigation"), ), body: Center( child: (_children[_index ]), ), bottomNavigationBar: BottomNavigationBar( onTap: onTabTapped, currentIndex: _currentIndex, items: [ BottomNavigationBarItem( icon: Icon(Icons.looks_one), title: Text('First'), ), BottomNavigationBarItem( icon: Icon(Icons.looks_two), title: Text('Second'), ), BottomNavigationBarItem( icon: Icon(Icons.looks_3), title: Text('Third'), ) ], ), ); } void onTabTapped(int index) { setState(() { _index = index; }); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.