Split button
A split button keeps a frequent action one press away and puts related alternatives in a menu. Name the first part so people know what will happen before opening the menu.
Choose how to save
#Choose Save for the current draft. Open the adjacent menu and choose Save a copy to see a different confirmation.
components/split-button/appliance/save_options.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class SaveOptions extends StatefulWidget {
const SaveOptions({super.key});
@override
State<SaveOptions> createState() => _SaveOptionsState();
}
class _SaveOptionsState extends State<SaveOptions> {
String result = 'Unsaved draft';
@override
Widget build(BuildContext context) => Column(
mainAxisSize: MainAxisSize.min,
children: [
ApplianceSplitButton(
label: 'Save',
onPressed: () => setState(() => result = 'Draft saved'),
menuLabel: 'Save options',
actions: [
DesignSplitAction(
label: 'Save a copy',
onPressed: () => setState(() => result = 'Copy saved'),
),
],
),
const SizedBox(height: 12),
Text(result),
],
);
}
Parameters
ApplianceSplitButton API ↗label- Name of the primary action.
onPressed- Saves the current draft.
actions- Supplies the alternate save action.
menuLabel- Names the control that opens the alternate action.
Shared behaviour
- Keyboard and focus. Reach the primary action with Tab. Try the menu trigger, the arrow keys and Enter. Escape lets you leave a menu without choosing an action.
- Screen readers. The primary action and the menu trigger have separate names. The confirmation below the pair identifies which action ran.
- Direction and type. The menu trigger sits at the reading end of the pair. Open it with large text in the phone frame to inspect its alignment and label.