Skip to content

Feat: add nested submenus #69

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
35 changes: 33 additions & 2 deletions lib/src/pie_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class PieAction {
this.buttonTheme,
this.buttonThemeHovered,
required this.child,
}) : builder = null;
}) : builder = null,
subActions = null,
isSubmenu = false;

/// Creates a [PieAction] with a builder which provides
/// whether the action is hovered or not as a parameter.
Expand All @@ -26,7 +28,25 @@ class PieAction {
this.buttonTheme,
this.buttonThemeHovered,
required this.builder,
}) : child = null;
}) : child = null,
subActions = null,
isSubmenu = false;

/// Creates a [PieAction] that opens a submenu when selected.
///
/// Instead of triggering an action when selected, this will open
/// a nested menu with the provided [subActions] centered around this action.
PieAction.submenu({
required this.tooltip,
required List<PieAction> submenuActions,
this.buttonTheme,
this.buttonThemeHovered,
required this.child,
Function()? onSelectAction,
}) : builder = null,
onSelect = onSelectAction ?? (() {}),
subActions = submenuActions,
isSubmenu = true;

/// Widget to display on [PieCanvas] when this action is hovered.
final Widget tooltip;
Expand Down Expand Up @@ -54,4 +74,15 @@ class PieAction {
///
/// Useful for custom widgets instead of icons.
final Widget Function(bool hovered)? builder;

/// List of actions to display in the submenu when this action is selected.
///
/// Only applicable for submenu actions created with [PieAction.submenu].
final List<PieAction>? subActions;

/// Whether this action opens a submenu when selected.
///
/// If true, [onSelect] will be ignored and a submenu will be displayed
/// when this action is selected, centered around this action.
final bool isSubmenu;
}
Loading