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 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* **BREAKING** Removed `BottomSheet` and its related widgets and functions.
* **BREAKING** Removed `Snackbar`, `showSnackbar` and their related widgets. Use `InfoBar` and `displayInfoBar` instead.
* fix: do not close `InfoBar` twice ([#955](https://github.com/bdlukaa/fluent_ui/issues/955))
* fix: The `MenuFlyoutSubItem` in the `DropDownButton` was not displaying when hovered or pressed.

## 4.7.7

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
59 changes: 43 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,52 @@ 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,
);
}
}
Loading