From 44f7d4cfa231f55ced03827f1425d9465e1dfe33 Mon Sep 17 00:00:00 2001 From: Abbas Hussein Date: Tue, 14 Nov 2023 21:48:32 +0300 Subject: [PATCH 1/5] Update dropdown_button.dart --- lib/src/controls/inputs/dropdown_button.dart | 51 +++++++++++++++----- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/lib/src/controls/inputs/dropdown_button.dart b/lib/src/controls/inputs/dropdown_button.dart index 4624c51e4..c7d2b474b 100644 --- a/lib/src/controls/inputs/dropdown_button.dart +++ b/lib/src/controls/inputs/dropdown_button.dart @@ -337,19 +337,14 @@ class DropDownButtonState extends State { color: widget.menuColor, shape: widget.menuShape, items: widget.items.map((item) { + if (item is MenuFlyoutSubItem) { + return _buildMenuFlyoutISubItem(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 _buildMenuFlyoutItem(item, context); } + return item; }).toList(), ); @@ -357,4 +352,38 @@ class DropDownButtonState extends State { ); widget.onClose?.call(); } + + MenuFlyoutSubItem _buildMenuFlyoutISubItem(MenuFlyoutSubItem item) { + return MenuFlyoutSubItem( + key: item.key, + text: item.text, + items: (context) => item.items.call(context).map((item) { + if (widget.closeAfterClick && item is MenuFlyoutItem) { + return _buildMenuFlyoutItem(item, context); + } + return item; + }).toList(), + leading: item.leading, + trailing: item.trailing, + showBehavior: item.showBehavior, + showHoverDelay: item.showHoverDelay, + ); + } + + MenuFlyoutItem _buildMenuFlyoutItem( + 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, + ); + } } From 019b11e2a9ff4c7c80a0070936e491ba4b2e024f Mon Sep 17 00:00:00 2001 From: Abbas Hussein Date: Tue, 14 Nov 2023 22:30:06 +0300 Subject: [PATCH 2/5] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ce4d9f60..438fdd505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: MenuFlyoutSubItem was not displaying when hovered or pressing over in a DropdownButton. ## 4.7.7 From 93fad1c0c5096362c773eb910596c665d9ba753d Mon Sep 17 00:00:00 2001 From: Abbas Hussein Date: Sat, 18 Nov 2023 11:11:05 +0300 Subject: [PATCH 3/5] Fix MenuFlyoutSubItem Display Issue --- CHANGELOG.md | 2 +- lib/src/controls/flyouts/menu.dart | 5 +- lib/src/controls/inputs/dropdown_button.dart | 60 +------------------- 3 files changed, 6 insertions(+), 61 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 438fdd505..b9cca1199 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +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: MenuFlyoutSubItem was not displaying when hovered or pressing over in a DropdownButton. +* fix: the MenuFlyoutSubItem is not displaying when hovered or pressed. ## 4.7.7 diff --git a/lib/src/controls/flyouts/menu.dart b/lib/src/controls/flyouts/menu.dart index 1f2879234..1e136bfa4 100644 --- a/lib/src/controls/flyouts/menu.dart +++ b/lib/src/controls/flyouts/menu.dart @@ -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); + }, ), ); } diff --git a/lib/src/controls/inputs/dropdown_button.dart b/lib/src/controls/inputs/dropdown_button.dart index c7d2b474b..1b77e1c88 100644 --- a/lib/src/controls/inputs/dropdown_button.dart +++ b/lib/src/controls/inputs/dropdown_button.dart @@ -32,7 +32,6 @@ class DropDownButton extends StatefulWidget { this.title, this.trailing = _kDefaultDropdownButtonTrailing, this.verticalOffset = _kVerticalOffset, - this.closeAfterClick = true, this.disabled = false, this.focusNode, this.autofocus = false, @@ -85,13 +84,6 @@ class DropDownButton extends StatefulWidget { /// * [MenuFlyoutItemBuilder], which renders the given widget in the items list final List items; - /// Whether the flyout will be closed after an item is tapped. - /// - /// This is only effective on items that are [MenuFlyoutItem] - /// - /// Defaults to `true` - final bool closeAfterClick; - /// If `true`, the button won't be clickable. final bool disabled; @@ -199,12 +191,6 @@ class DropDownButton extends StatefulWidget { verticalOffset, defaultValue: _kVerticalOffset, )) - ..add(FlagProperty( - 'close after click', - value: closeAfterClick, - defaultValue: false, - ifFalse: 'do not close after click', - )) ..add(EnumProperty('placement', placement)) ..add(DiagnosticsProperty('menu shape', menuShape)) ..add(ColorProperty('menu color', menuColor)); @@ -336,54 +322,10 @@ class DropDownButtonState extends State { return MenuFlyout( color: widget.menuColor, shape: widget.menuShape, - items: widget.items.map((item) { - if (item is MenuFlyoutSubItem) { - return _buildMenuFlyoutISubItem(item); - } - - if (widget.closeAfterClick && item is MenuFlyoutItem) { - return _buildMenuFlyoutItem(item, context); - } - - return item; - }).toList(), + items: widget.items, ); }, ); widget.onClose?.call(); } - - MenuFlyoutSubItem _buildMenuFlyoutISubItem(MenuFlyoutSubItem item) { - return MenuFlyoutSubItem( - key: item.key, - text: item.text, - items: (context) => item.items.call(context).map((item) { - if (widget.closeAfterClick && item is MenuFlyoutItem) { - return _buildMenuFlyoutItem(item, context); - } - return item; - }).toList(), - leading: item.leading, - trailing: item.trailing, - showBehavior: item.showBehavior, - showHoverDelay: item.showHoverDelay, - ); - } - - MenuFlyoutItem _buildMenuFlyoutItem( - 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, - ); - } } From 059e057956178396c41205355f24fbb280698264 Mon Sep 17 00:00:00 2001 From: Abbas Hussein Date: Mon, 20 Nov 2023 22:34:31 +0300 Subject: [PATCH 4/5] fix dropdown_button issue --- CHANGELOG.md | 2 +- lib/src/controls/inputs/dropdown_button.dart | 58 +++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9cca1199..a7baa1967 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +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 is not displaying when hovered or pressed. +* fix: The `MenuFlyoutSubItem` in the `DropDownButton` was not displaying when hovered or pressed. ## 4.7.7 diff --git a/lib/src/controls/inputs/dropdown_button.dart b/lib/src/controls/inputs/dropdown_button.dart index 1b77e1c88..253b85fb8 100644 --- a/lib/src/controls/inputs/dropdown_button.dart +++ b/lib/src/controls/inputs/dropdown_button.dart @@ -32,6 +32,7 @@ class DropDownButton extends StatefulWidget { this.title, this.trailing = _kDefaultDropdownButtonTrailing, this.verticalOffset = _kVerticalOffset, + this.closeAfterClick = true, this.disabled = false, this.focusNode, this.autofocus = false, @@ -84,6 +85,13 @@ class DropDownButton extends StatefulWidget { /// * [MenuFlyoutItemBuilder], which renders the given widget in the items list final List items; + /// Whether the flyout will be closed after an item is tapped. + /// + /// This is only effective on items that are [MenuFlyoutItem] + /// + /// Defaults to `true` + final bool closeAfterClick; + /// If `true`, the button won't be clickable. final bool disabled; @@ -191,6 +199,12 @@ class DropDownButton extends StatefulWidget { verticalOffset, defaultValue: _kVerticalOffset, )) + ..add(FlagProperty( + 'close after click', + value: closeAfterClick, + defaultValue: false, + ifFalse: 'do not close after click', + )) ..add(EnumProperty('placement', placement)) ..add(DiagnosticsProperty('menu shape', menuShape)) ..add(ColorProperty('menu color', menuColor)); @@ -322,10 +336,52 @@ class DropDownButtonState extends State { return MenuFlyout( color: widget.menuColor, shape: widget.menuShape, - items: widget.items, + 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, + ); + } } From 148813cf4d7bbd7722bfb9d2b00c93cbf825b5c2 Mon Sep 17 00:00:00 2001 From: Abbas Hussein Date: Tue, 28 Nov 2023 14:13:29 +0300 Subject: [PATCH 5/5] Update dropdown_button.dart --- lib/src/controls/inputs/dropdown_button.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/controls/inputs/dropdown_button.dart b/lib/src/controls/inputs/dropdown_button.dart index 253b85fb8..e03b74be8 100644 --- a/lib/src/controls/inputs/dropdown_button.dart +++ b/lib/src/controls/inputs/dropdown_button.dart @@ -336,7 +336,8 @@ class DropDownButtonState extends State { return MenuFlyout( color: widget.menuColor, shape: widget.menuShape, - items: widget.items.map((item) => transformItem(item, context)).toList(), + items: + widget.items.map((item) => transformItem(item, context)).toList(), ); }, );