Menu
A menu keeps related commands together until they are needed. Group options under a trigger whose name tells readers what they can change.
Choose a sort order
#Open Sort files and choose Date. The current order appears below the trigger. Reopen the menu and choose Name to switch back.
components/menu/appliance/sort_files.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class SortFiles extends StatefulWidget {
const SortFiles({super.key});
@override
State<SortFiles> createState() => _SortFilesState();
}
class _SortFilesState extends State<SortFiles> {
String order = 'Name';
@override
Widget build(BuildContext context) => Column(
mainAxisSize: MainAxisSize.min,
children: [
ApplianceMenu(
semanticLabel: 'Sort files',
entries: [
for (final sort in ['Name', 'Date'])
DesignMenuEntry(
label: sort,
onPressed: () => setState(() => order = sort),
),
],
builder: (_, anchor) =>
ApplianceButton('Sort files', onPressed: anchor.toggle),
),
const SizedBox(height: 12),
Text('Sort order: $order'),
],
);
}
Parameters
ApplianceMenu API ↗entries- The commands available in the menu.
builder- Builds the menu trigger.
semanticLabel- Names the open menu.
Shared behaviour
- Keyboard and focus. Open the menu with Enter. Use the arrow keys or Tab to reach a choice and activate it. Try Escape to dismiss without choosing.
- Screen readers. Read the two named options, then read the new sort order beneath the trigger.
- Direction and type. Menu labels use the surrounding direction and text size. On a narrow screen check the placement relative to the trigger.