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

Added Tooltip to BottomNavyBar.items #91

Merged
merged 2 commits into from
Jul 25, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 7.0.0

- Added customizations options for text and background colors of the bottom navigation bar item as `activeBackgroundColor`, `activeTextColor`.
- Added support for `tooltipText` to show a tooltip when the item is long pressed.

## 6.1.0

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ The navigation bar uses your current theme, but you are free to customize it.
- `textAlign` - property to change the alignment of the item title
- `activeBackgroundColor` - the active item's background color
- `activeTextColor` - the active item's text color
- `tooltipText` - the tooltip text that will appear when the item is long pressed

## Getting Started

Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class _MyHomePageState extends State<MyHomePage> {
icon: Icon(Icons.apps),
title: Text('Home'),
activeColor: Colors.red,
textAlign: TextAlign.center,
textAlign: TextAlign.center
),
BottomNavyBarItem(
icon: Icon(Icons.people),
Expand Down
11 changes: 10 additions & 1 deletion lib/bottom_navy_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class _ItemWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Semantics(
Semantics semantic = Semantics(
container: true,
selected: isSelected,
child: AnimatedContainer(
Expand Down Expand Up @@ -253,6 +253,12 @@ class _ItemWidget extends StatelessWidget {
),
),
);
return item.tooltipText == null
? semantic
: Tooltip(
message: item.tooltipText!,
child: semantic,
);
}
}

Expand All @@ -266,6 +272,7 @@ class BottomNavyBarItem {
this.inactiveColor,
this.activeTextColor,
this.activeBackgroundColor,
this.tooltipText,
});

/// Defines this item's icon which is placed in the right side of the [title].
Expand Down Expand Up @@ -295,4 +302,6 @@ class BottomNavyBarItem {
///
/// Will fallback to [activeColor] with opacity 0.2 when null
final Color? activeBackgroundColor;
/// Will show a tooltip for the item if provided.
final String? tooltipText;
}
15 changes: 15 additions & 0 deletions test/bottom_navy_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ final List<BottomNavyBarItem> dummyItems = <BottomNavyBarItem>[
textAlign: TextAlign.center,
activeTextColor: Colors.white,
activeBackgroundColor: Colors.red,
tooltipText: 'Item 1',
),
BottomNavyBarItem(
icon: Icon(Icons.people),
Expand Down Expand Up @@ -150,4 +151,18 @@ void main() {
expect(bottomNavyBar.items[0].activeTextColor, Colors.white);
expect(bottomNavyBar.items[0].activeBackgroundColor, Colors.red);
});

testWidgets('should show a tooltip message when tooltipText is not null', (WidgetTester tester) async {
await tester.pumpWidget(
buildNavyBarBoilerplate(
onItemSelected: onItemSelected,
),
);

final BottomNavyBar bottomNavyBar = tester.firstWidget<BottomNavyBar>(find.byType(BottomNavyBar));

expect(bottomNavyBar.items[0].tooltipText, 'Item 1');
// if tooltipText is null, tooltip should be null
expect(bottomNavyBar.items[1].tooltipText, null);
});
}
Loading