Skip to content

Commit e6c2d2f

Browse files
Merge pull request #91 from shahabhm/issue_50_1
Added Tooltip to BottomNavyBar.items
2 parents e4589cb + 9c079c2 commit e6c2d2f

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 7.0.0
22

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

56
## 6.1.0
67

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ The navigation bar uses your current theme, but you are free to customize it.
4343
- `textAlign` - property to change the alignment of the item title
4444
- `activeBackgroundColor` - the active item's background color
4545
- `activeTextColor` - the active item's text color
46+
- `tooltipText` - the tooltip text that will appear when the item is long pressed
4647

4748
## Getting Started
4849

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class _MyHomePageState extends State<MyHomePage> {
6262
icon: Icon(Icons.apps),
6363
title: Text('Home'),
6464
activeColor: Colors.red,
65-
textAlign: TextAlign.center,
65+
textAlign: TextAlign.center
6666
),
6767
BottomNavyBarItem(
6868
icon: Icon(Icons.people),

lib/bottom_navy_bar.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class _ItemWidget extends StatelessWidget {
166166

167167
@override
168168
Widget build(BuildContext context) {
169-
return Semantics(
169+
Semantics semantic = Semantics(
170170
container: true,
171171
selected: isSelected,
172172
child: AnimatedContainer(
@@ -253,6 +253,12 @@ class _ItemWidget extends StatelessWidget {
253253
),
254254
),
255255
);
256+
return item.tooltipText == null
257+
? semantic
258+
: Tooltip(
259+
message: item.tooltipText!,
260+
child: semantic,
261+
);
256262
}
257263
}
258264

@@ -266,6 +272,7 @@ class BottomNavyBarItem {
266272
this.inactiveColor,
267273
this.activeTextColor,
268274
this.activeBackgroundColor,
275+
this.tooltipText,
269276
});
270277

271278
/// Defines this item's icon which is placed in the right side of the [title].
@@ -295,4 +302,6 @@ class BottomNavyBarItem {
295302
///
296303
/// Will fallback to [activeColor] with opacity 0.2 when null
297304
final Color? activeBackgroundColor;
305+
/// Will show a tooltip for the item if provided.
306+
final String? tooltipText;
298307
}

test/bottom_navy_bar_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ final List<BottomNavyBarItem> dummyItems = <BottomNavyBarItem>[
1010
textAlign: TextAlign.center,
1111
activeTextColor: Colors.white,
1212
activeBackgroundColor: Colors.red,
13+
tooltipText: 'Item 1',
1314
),
1415
BottomNavyBarItem(
1516
icon: Icon(Icons.people),
@@ -150,4 +151,18 @@ void main() {
150151
expect(bottomNavyBar.items[0].activeTextColor, Colors.white);
151152
expect(bottomNavyBar.items[0].activeBackgroundColor, Colors.red);
152153
});
154+
155+
testWidgets('should show a tooltip message when tooltipText is not null', (WidgetTester tester) async {
156+
await tester.pumpWidget(
157+
buildNavyBarBoilerplate(
158+
onItemSelected: onItemSelected,
159+
),
160+
);
161+
162+
final BottomNavyBar bottomNavyBar = tester.firstWidget<BottomNavyBar>(find.byType(BottomNavyBar));
163+
164+
expect(bottomNavyBar.items[0].tooltipText, 'Item 1');
165+
// if tooltipText is null, tooltip should be null
166+
expect(bottomNavyBar.items[1].tooltipText, null);
167+
});
153168
}

0 commit comments

Comments
 (0)