Skip to content

Commit

Permalink
Add onSecondaryTap
Browse files Browse the repository at this point in the history
  • Loading branch information
aroxu committed Nov 23, 2023
1 parent c1fa85a commit 691b0ca
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/src/models/sidebarx_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class SidebarXItem {
this.iconWidget,
this.onTap,
this.onLongPress,
this.onSecondaryTap,
}) : assert(
(icon != null || iconWidget != null) &&
(icon == null || iconWidget == null),
Expand All @@ -18,4 +19,5 @@ class SidebarXItem {
final Widget? iconWidget;
final Function()? onTap;
final Function()? onLongPress;
final Function()? onSecondaryTap;
}
12 changes: 12 additions & 0 deletions lib/src/sidebarx_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class _SidebarXState extends State<SidebarX>
selected: widget.controller.selectedIndex == index,
onTap: () => _onItemSelected(item, index),
onLongPress: () => _onItemLongPressSelected(item, index),
onSecondaryTap: () =>
_onItemSecondaryTapSelected(item, index),
);
},
),
Expand Down Expand Up @@ -166,6 +168,8 @@ class _SidebarXState extends State<SidebarX>
onTap: () => _onFooterItemSelected(item, index),
onLongPress: () =>
_onFooterItemLongPressSelected(item, index),
onSecondaryTap: () =>
_onFooterItemSecondaryTapSelected(item, index),
);
},
),
Expand All @@ -189,6 +193,10 @@ class _SidebarXState extends State<SidebarX>
item.onLongPress?.call();
}

void _onFooterItemSecondaryTapSelected(SidebarXItem item, int index) {
item.onSecondaryTap?.call();
}

void _onItemSelected(SidebarXItem item, int index) {
item.onTap?.call();
widget.controller.selectIndex(index);
Expand All @@ -198,6 +206,10 @@ class _SidebarXState extends State<SidebarX>
item.onLongPress?.call();
}

void _onItemSecondaryTapSelected(SidebarXItem item, int index) {
item.onSecondaryTap?.call();
}

Widget _buildToggleButton(
SidebarXTheme sidebarXTheme,
IconData collapseIcon,
Expand Down
3 changes: 3 additions & 0 deletions lib/src/widgets/sidebarx_cell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class SidebarXCell extends StatefulWidget {
required this.theme,
required this.onTap,
required this.onLongPress,
required this.onSecondaryTap,
required this.animationController,
}) : super(key: key);

Expand All @@ -19,6 +20,7 @@ class SidebarXCell extends StatefulWidget {
final SidebarXTheme theme;
final VoidCallback onTap;
final VoidCallback onLongPress;
final VoidCallback onSecondaryTap;
final AnimationController animationController;

@override
Expand Down Expand Up @@ -64,6 +66,7 @@ class _SidebarXCellState extends State<SidebarXCell> {
child: GestureDetector(
onTap: widget.onTap,
onLongPress: widget.onLongPress,
onSecondaryTap: widget.onSecondaryTap,
behavior: HitTestBehavior.opaque,
child: Container(
decoration: decoration?.copyWith(
Expand Down

0 comments on commit 691b0ca

Please sign in to comment.