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

Fix ISSUE: MenuFlyoutSubItem was not displaying when hovered or pressing over in a DropdownButton. #964

Merged
merged 6 commits into from
Nov 30, 2023
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [next]

* fix: The `MenuFlyoutSubItem` in the `DropDownButton` was not displaying when hovered or pressed. ([#964](https://github.com/bdlukaa/fluent_ui/pull/964))

## 4.8.1

* feat: Added `NavigationPane.toggleable` ([#973](https://github.com/bdlukaa/fluent_ui/issues/973))
Expand Down
5 changes: 4 additions & 1 deletion lib/src/controls/flyouts/menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ class MenuFlyoutItem extends MenuFlyoutItemBase {
data: const IconThemeData(size: 12.0),
child: trailing ?? const SizedBox.shrink(),
),
onPressed: onPressed,
onPressed: () {
onPressed?.call();
Navigator.maybePop(context);
},
),
);
}
Expand Down
60 changes: 44 additions & 16 deletions lib/src/controls/inputs/dropdown_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -336,25 +336,53 @@ class DropDownButtonState extends State<DropDownButton> {
return MenuFlyout(
color: widget.menuColor,
shape: widget.menuShape,
items: widget.items.map((item) {
if (widget.closeAfterClick && item is MenuFlyoutItem) {
return MenuFlyoutItem(
onPressed: () {
Navigator.of(context).pop();
item.onPressed?.call();
},
key: item.key,
leading: item.leading,
text: item.text,
trailing: item.trailing,
selected: item.selected,
);
}
return item;
}).toList(),
items:
widget.items.map((item) => transformItem(item, context)).toList(),
);
},
);
widget.onClose?.call();
}

MenuFlyoutItemBase transformItem(
MenuFlyoutItemBase item,
BuildContext context,
) {
if (item is MenuFlyoutSubItem) {
return _createSubMenuItem(item);
} else if (widget.closeAfterClick && item is MenuFlyoutItem) {
return _createMenuItem(item, context);
} else {
return item;
}
}

MenuFlyoutSubItem _createSubMenuItem(MenuFlyoutSubItem item) {
return MenuFlyoutSubItem(
key: item.key,
text: item.text,
items: (context) => item.items
.call(context)
.map((item) => transformItem(item, context))
.toList(),
leading: item.leading,
trailing: item.trailing,
showBehavior: item.showBehavior,
showHoverDelay: item.showHoverDelay,
);
}

MenuFlyoutItem _createMenuItem(MenuFlyoutItem item, BuildContext context) {
return MenuFlyoutItem(
onPressed: () {
Navigator.of(context).pop();
item.onPressed?.call();
},
key: item.key,
leading: item.leading,
text: item.text,
trailing: item.trailing,
selected: item.selected,
);
}
}