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

[FEATURE] Seeing itemName in tooltip when hovering over the item #20

Merged
merged 2 commits into from
Aug 3, 2022
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
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class _MyHomePageState extends State<MyHomePage> {
// print(mode);
// },
style: SideMenuStyle(
// showTooltipOverItemsName: true,
displayMode: SideMenuDisplayMode.auto,
hoverColor: Colors.blue[100],
selectedColor: Colors.lightBlue,
Expand Down Expand Up @@ -95,6 +96,7 @@ class _MyHomePageState extends State<MyHomePage> {
'3',
style: TextStyle(color: Colors.white),
),
// tooltipContent: "Home",
),
SideMenuItem(
priority: 1,
Expand Down
63 changes: 37 additions & 26 deletions lib/src/side_menu_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SideMenuItem extends StatefulWidget {
required this.priority,
this.badgeContent,
this.badgeColor,
this.tooltipContent,
}) : super(key: key);

/// A function that call when tap on [SideMenuItem]
Expand All @@ -41,6 +42,10 @@ class SideMenuItem extends StatefulWidget {
/// Background color for badge
final Color? badgeColor;

/// Content of the tooltip - if not filled, the [title] will
/// be used. [showTooltipOverItemsName] must be set to true.
final String? tooltipContent;

@override
_SideMenuItemState createState() => _SideMenuItemState();
}
Expand Down Expand Up @@ -134,33 +139,39 @@ class _SideMenuItemState extends State<SideMenuItem> {
child: ValueListenableBuilder(
valueListenable: Global.displayModeState,
builder: (context, value, child) {
return Padding(
padding: EdgeInsets.symmetric(
vertical: value == SideMenuDisplayMode.compact ? 0 : 8),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: Global.style.itemInnerSpacing,
),
_generateIcon(widget.icon),
SizedBox(
width: Global.style.itemInnerSpacing,
),
if (value == SideMenuDisplayMode.open)
Expanded(
child: Text(
widget.title,
style: widget.priority == currentPage.ceil()
? const TextStyle(
fontSize: 17, color: Colors.black)
.merge(Global.style.selectedTitleTextStyle)
: const TextStyle(
fontSize: 17, color: Colors.black54)
.merge(Global.style.unselectedTitleTextStyle),
),
return Tooltip(
message: (value == SideMenuDisplayMode.compact
&& Global.style.showTooltipOverItemsName)
? widget.tooltipContent ?? widget.title
: "",
child: Padding(
padding: EdgeInsets.symmetric(
vertical: value == SideMenuDisplayMode.compact ? 0 : 8),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: Global.style.itemInnerSpacing,
),
],
_generateIcon(widget.icon),
SizedBox(
width: Global.style.itemInnerSpacing,
),
if (value == SideMenuDisplayMode.open)
Expanded(
child: Text(
widget.title,
style: widget.priority == currentPage.ceil()
? const TextStyle(
fontSize: 17, color: Colors.black)
.merge(Global.style.selectedTitleTextStyle)
: const TextStyle(
fontSize: 17, color: Colors.black54)
.merge(Global.style.unselectedTitleTextStyle),
),
),
],
),
),
);
},
Expand Down
7 changes: 7 additions & 0 deletions lib/src/side_menu_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class SideMenuStyle {
/// Border Radius of menu item
BorderRadius itemBorderRadius;

/// Property that will show user itemName in
/// Tooltip when they'll hover over the item
/// This property will only work if current
/// [SideMenuDisplayMode] is set compact
bool showTooltipOverItemsName;

/// Style class to configure [SideMenu]
SideMenuStyle({
this.openSideMenuWidth = 300,
Expand All @@ -75,5 +81,6 @@ class SideMenuStyle {
this.itemBorderRadius = const BorderRadius.all(
Radius.circular(5.0),
),
this.showTooltipOverItemsName = false,
});
}