|
| 1 | +import 'package:bottom_navy_bar/bottom_navy_bar.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | + |
| 4 | +class BottomNavyBarExample extends StatefulWidget { |
| 5 | + const BottomNavyBarExample({ Key? key }) : super(key: key); |
| 6 | + |
| 7 | + @override |
| 8 | + _BottomNavyBarExampleState createState() => _BottomNavyBarExampleState(); |
| 9 | +} |
| 10 | + |
| 11 | +class _BottomNavyBarExampleState extends State<BottomNavyBarExample> { |
| 12 | + int _selectedIndex = 0; |
| 13 | + PageController _pageController = PageController(initialPage: 0); |
| 14 | + |
| 15 | + @override |
| 16 | + Widget build(BuildContext context) { |
| 17 | + return Scaffold( |
| 18 | + body: Container( |
| 19 | + child: PageView( |
| 20 | + controller: _pageController, |
| 21 | + onPageChanged: (index) { |
| 22 | + setState(() { |
| 23 | + _selectedIndex = index; |
| 24 | + }); |
| 25 | + }, |
| 26 | + children: <Widget>[ |
| 27 | + _buildPage( |
| 28 | + icon: Icons.apps, |
| 29 | + title: '@theflutterlover', |
| 30 | + color: Colors.red, |
| 31 | + ), |
| 32 | + _buildPage( |
| 33 | + icon: Icons.person, |
| 34 | + title: 'Profile', |
| 35 | + color: Colors.pink, |
| 36 | + ), |
| 37 | + _buildPage( |
| 38 | + icon: Icons.message, |
| 39 | + title: 'Messages', |
| 40 | + color: Colors.orange, |
| 41 | + ), |
| 42 | + _buildPage( |
| 43 | + icon: Icons.settings, |
| 44 | + title: 'Settings', |
| 45 | + color: Colors.blue, |
| 46 | + ), |
| 47 | + ], |
| 48 | + ), |
| 49 | + ), |
| 50 | + bottomNavigationBar: BottomNavyBar( |
| 51 | + selectedIndex: _selectedIndex, |
| 52 | + showElevation: false, |
| 53 | + onItemSelected: (index) => setState(() { |
| 54 | + _selectedIndex = index; |
| 55 | + _pageController.animateToPage(index, |
| 56 | + duration: Duration(milliseconds: 300), curve: Curves.ease); |
| 57 | + }), |
| 58 | + items: [ |
| 59 | + BottomNavyBarItem( |
| 60 | + icon: Icon(Icons.apps), |
| 61 | + title: Text('Home'), |
| 62 | + activeColor: Colors.red, |
| 63 | + ), |
| 64 | + BottomNavyBarItem( |
| 65 | + icon: Icon(Icons.people), |
| 66 | + title: Text('Users'), |
| 67 | + activeColor: Colors.purpleAccent |
| 68 | + ), |
| 69 | + BottomNavyBarItem( |
| 70 | + icon: Icon(Icons.message), |
| 71 | + title: Text('Messages'), |
| 72 | + activeColor: Colors.pink |
| 73 | + ), |
| 74 | + BottomNavyBarItem( |
| 75 | + icon: Icon(Icons.settings), |
| 76 | + title: Text('Settings'), |
| 77 | + activeColor: Colors.blue |
| 78 | + ), |
| 79 | + ], |
| 80 | + ) |
| 81 | + ); |
| 82 | + } |
| 83 | + |
| 84 | + _buildPage ({ IconData? icon, String? title, Color? color }) { |
| 85 | + return Container( |
| 86 | + color: color, |
| 87 | + child: Center( |
| 88 | + child: Column( |
| 89 | + mainAxisSize: MainAxisSize.min, |
| 90 | + children: <Widget>[ |
| 91 | + Icon(icon, size: 200.0, color: Colors.white), |
| 92 | + Text(title!, style: TextStyle(color: Colors.white, fontSize: 20)), |
| 93 | + ], |
| 94 | + ), |
| 95 | + ), |
| 96 | + ); |
| 97 | + } |
| 98 | +} |
0 commit comments