diff --git a/lib/widgets/desktop/context_menu.dart b/lib/widgets/desktop/context_menu.dart index 9847a81c0..35eb89661 100644 --- a/lib/widgets/desktop/context_menu.dart +++ b/lib/widgets/desktop/context_menu.dart @@ -47,8 +47,8 @@ const double _mornyeMenuWidth = 280; /// /// Material opens the M3E menu popup of More buttons, or under reduced /// motion a [MenuAnchor] with the M3 Expressive menu container; Mornye -/// opens the dense [MornyeContextMenu]. Empty groups are dropped and the -/// remaining ones are set apart (dividers, or separate M3E surfaces). The +/// opens the dense [MornyeContextMenu]. Empty groups are dropped and a +/// divider sets the remaining ones apart, inside the one menu surface. The /// chosen action runs once the menu has been dismissed, so it can open its /// own dialog or sheet. The future completes after that action has started, /// with whether a row was chosen. @@ -143,29 +143,28 @@ Future _showExpressiveContextMenu( } var index = 0; - final children = [ - for (final group in groups) - M3EMenuGroup( - children: [ - for (final action in group) - if (action.checked) - M3EMenuSelectable( - label: action.label, - value: index++, - leading: AppIcon(action.icon, size: 20), - selected: true, - enabled: action.onSelected != null, - ) - else - M3EMenuEntry( - label: action.label, - value: index++, - leading: AppIcon(action.icon, size: 20), - isDestructive: action.destructive, - enabled: action.onSelected != null, - ), - ], - ), + // One surface, as a menu is one object: a divider sets the groups apart. + final children = [ + for (final (position, group) in groups.indexed) ...[ + if (position > 0) const M3EMenuDivider(), + for (final action in group) + if (action.checked) + M3EMenuSelectable( + label: action.label, + value: index++, + leading: AppIcon(action.icon, size: 20), + selected: true, + enabled: action.onSelected != null, + ) + else + M3EMenuEntry( + label: action.label, + value: index++, + leading: AppIcon(action.icon, size: 20), + isDestructive: action.destructive, + enabled: action.onSelected != null, + ), + ], ]; late final OverlayEntry entry; // Once dismissed, the closing menu lets clicks through to the page. diff --git a/test/material_theme_roles_test.dart b/test/material_theme_roles_test.dart index a402f90d0..2da7a315e 100644 --- a/test/material_theme_roles_test.dart +++ b/test/material_theme_roles_test.dart @@ -303,6 +303,40 @@ void main() { ); expect(find.byType(Divider), findsOneWidget); }); + + testWidgets('a menu keeps its groups on one surface, with a divider', ( + tester, + ) async { + ContextMenuAction action(String label) => ContextMenuAction( + icon: Icons.queue_music, + label: label, + onSelected: () {}, + ); + await tester.pumpWidget( + _host( + Builder( + builder: (context) => TextButton( + onPressed: () => showContextMenu( + context, + position: const Offset(100, 100), + groups: [ + [action('Save offline'), action('Export')], + [action('Edit order')], + ], + ), + child: const Text('Open'), + ), + ), + ), + ); + await tester.tap(find.text('Open')); + await tester.pumpAndSettle(); + + // The package draws a divider only inside a surface, between its rows. + final divider = tester.getCenter(find.byType(M3EMenuDividerWidget)).dy; + expect(divider, greaterThan(tester.getCenter(find.text('Export')).dy)); + expect(divider, lessThan(tester.getCenter(find.text('Edit order')).dy)); + }); }); group('settings fills', () {