From ab1ab1356aebfbc4e2024571a2ddfef0fea6b00c Mon Sep 17 00:00:00 2001 From: shahabam Date: Thu, 15 Jul 2021 15:33:15 +0430 Subject: [PATCH 1/2] add tooltip --- example/lib/main.dart | 1 + lib/bottom_navy_bar.dart | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 060b489..7f4d4dd 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -63,6 +63,7 @@ class _MyHomePageState extends State { title: Text('Home'), activeColor: Colors.red, textAlign: TextAlign.center, + tooltipText: "Home Sweet Home", ), BottomNavyBarItem( icon: Icon(Icons.people), diff --git a/lib/bottom_navy_bar.dart b/lib/bottom_navy_bar.dart index cdc9209..183fefd 100644 --- a/lib/bottom_navy_bar.dart +++ b/lib/bottom_navy_bar.dart @@ -166,7 +166,7 @@ class _ItemWidget extends StatelessWidget { @override Widget build(BuildContext context) { - return Semantics( + Semantics semantic = Semantics( container: true, selected: isSelected, child: AnimatedContainer( @@ -253,6 +253,12 @@ class _ItemWidget extends StatelessWidget { ), ), ); + return item.tooltipText == null + ? semantic + : Tooltip( + message: item.tooltipText!, + child: semantic, + ); } } @@ -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]. @@ -295,4 +302,6 @@ class BottomNavyBarItem { /// /// Will fallback to [activeColor] with opacity 0.2 when null final Color? activeBackgroundColor; + /// Will show a tooltip for icon if provided. + final String? tooltipText; } From 9c079c2f73f3e429b9be1172b5f45860a307d639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Pedro?= <42675180+antonio-pedro99@users.noreply.github.com> Date: Fri, 26 Jul 2024 02:45:27 +0530 Subject: [PATCH 2/2] added tests and fixed conflicts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: António Pedro <42675180+antonio-pedro99@users.noreply.github.com> --- CHANGELOG.md | 1 + README.md | 1 + example/lib/main.dart | 3 +-- lib/bottom_navy_bar.dart | 2 +- test/bottom_navy_bar_test.dart | 15 +++++++++++++++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19025f4..7b366e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index b50fd9c..f7d7373 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/example/lib/main.dart b/example/lib/main.dart index 7f4d4dd..a1b8b92 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -62,8 +62,7 @@ class _MyHomePageState extends State { icon: Icon(Icons.apps), title: Text('Home'), activeColor: Colors.red, - textAlign: TextAlign.center, - tooltipText: "Home Sweet Home", + textAlign: TextAlign.center ), BottomNavyBarItem( icon: Icon(Icons.people), diff --git a/lib/bottom_navy_bar.dart b/lib/bottom_navy_bar.dart index 183fefd..47ffeb8 100644 --- a/lib/bottom_navy_bar.dart +++ b/lib/bottom_navy_bar.dart @@ -302,6 +302,6 @@ class BottomNavyBarItem { /// /// Will fallback to [activeColor] with opacity 0.2 when null final Color? activeBackgroundColor; - /// Will show a tooltip for icon if provided. + /// Will show a tooltip for the item if provided. final String? tooltipText; } diff --git a/test/bottom_navy_bar_test.dart b/test/bottom_navy_bar_test.dart index 65c1840..0891005 100644 --- a/test/bottom_navy_bar_test.dart +++ b/test/bottom_navy_bar_test.dart @@ -10,6 +10,7 @@ final List dummyItems = [ textAlign: TextAlign.center, activeTextColor: Colors.white, activeBackgroundColor: Colors.red, + tooltipText: 'Item 1', ), BottomNavyBarItem( icon: Icon(Icons.people), @@ -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(find.byType(BottomNavyBar)); + + expect(bottomNavyBar.items[0].tooltipText, 'Item 1'); + // if tooltipText is null, tooltip should be null + expect(bottomNavyBar.items[1].tooltipText, null); + }); }