fix(menu): keep a Material menu's groups on one surface

A menu with several groups, such as Sort and More on a playlist page,
opened as separate panels with a gap between them, which read as two
menus. The groups now share the one menu surface with a divider between
them, as the reduced motion menu already drew them.
This commit is contained in:
zarzet committed 2026-11-20 02:31:55 +07:00
1 parent 6aa51c0902
commit fa983e39a4
2 files changed
+58 -25

No files matched your search

+24 -25
View File
@@ -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<bool> _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 = <M3EMenuNode>[
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.
+34
View File
@@ -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', () {