Skip to content

Commit

Permalink
Fix ISSUE: MenuFlyoutSubItem was not displaying when hovered or press…
Browse files Browse the repository at this point in the history
…ing over in a DropdownButton. (#964)
  • Loading branch information
bdlukaa authored Nov 30, 2023
2 parents 529ecc7 + bc287ba commit 31b0fe0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 17 deletions.
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,
);
}
}

0 comments on commit 31b0fe0

Please sign in to comment.