Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to override item width and item selected width #75

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ A beautiful and animated bottom navigation. The navigation bar use your current
- `iconSize` - the item icon's size
- `items` - navigation items, required more than one item and less than six
- `selectedIndex` - the current item index. Use this to change the selected item. Default to zero
- `itemWidth` - changes the width of the item. Defaults to 50.
- `itemSelectedWidth` - changes the width of the selected item. Defaults to 130.
- `onItemSelected` - required to listen when a item is tapped it provide the selected item's index
- `backgroundColor` - the navigation bar's background color
- `showElevation` - if false the appBar's elevation will be removed
Expand Down
22 changes: 19 additions & 3 deletions lib/bottom_navy_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class BottomNavyBar extends StatelessWidget {
BottomNavyBar({
Key key,
this.selectedIndex = 0,
this.itemSelectedWidth = 130,
this.itemWidth = 50,
Comment on lines +16 to +17
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @davidpatrickcoleman
Thanks for this amazing contibution. Since this is a new feature could you please add tests to prevent this feature to break in the future?
Thank you

Sorry for the later feedback!

this.showElevation = true,
this.iconSize = 24,
this.backgroundColor,
Expand All @@ -34,6 +36,12 @@ class BottomNavyBar extends StatelessWidget {
/// the item being selected. Defaults to zero.
final int selectedIndex;

// The width of selected item. Defaults to 130.
final double itemSelectedWidth;

// The width of item. Defaults to 50.
final double itemWidth;

/// The icon size of all items. Defaults to 24.
final double iconSize;

Expand Down Expand Up @@ -101,6 +109,8 @@ class BottomNavyBar extends StatelessWidget {
isSelected: index == selectedIndex,
backgroundColor: bgColor,
itemCornerRadius: itemCornerRadius,
itemWidth: itemWidth,
itemSelectedWidth: itemSelectedWidth,
animationDuration: animationDuration,
curve: curve,
),
Expand All @@ -119,6 +129,8 @@ class _ItemWidget extends StatelessWidget {
final BottomNavyBarItem item;
final Color backgroundColor;
final double itemCornerRadius;
final double itemSelectedWidth;
final double itemWidth;
final Duration animationDuration;
final Curve curve;

Expand All @@ -129,15 +141,19 @@ class _ItemWidget extends StatelessWidget {
@required this.backgroundColor,
@required this.animationDuration,
@required this.itemCornerRadius,
@required this.itemWidth,
@required this.itemSelectedWidth,
@required this.iconSize,
this.curve = Curves.linear,
}) : assert(isSelected != null),
assert(item != null),
assert(backgroundColor != null),
assert(animationDuration != null),
assert(itemCornerRadius != null),
assert(iconSize != null),
assert(itemWidth != null),
assert(itemSelectedWidth != null),
assert(curve != null),
assert(iconSize != null),
super(key: key);

@override
Expand All @@ -146,7 +162,7 @@ class _ItemWidget extends StatelessWidget {
container: true,
selected: isSelected,
child: AnimatedContainer(
width: isSelected ? 130 : 50,
width: isSelected ? itemSelectedWidth : itemWidth,
height: double.maxFinite,
duration: animationDuration,
curve: curve,
Expand All @@ -159,7 +175,7 @@ class _ItemWidget extends StatelessWidget {
scrollDirection: Axis.horizontal,
physics: NeverScrollableScrollPhysics(),
child: Container(
width: isSelected ? 130 : 50,
width: isSelected ? itemSelectedWidth : itemWidth,
padding: EdgeInsets.symmetric(horizontal: 8),
child: Row(
mainAxisSize: MainAxisSize.max,
Expand Down