Anchor desktop Files and Runs menus
Use Material popup menus for file actions and anchor Runs sorting choices to the sort button while retaining the phone fallback. Update callers, tests, and implementation notes to match the desktop behavior.
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../adaptive/host.dart';
|
||||
|
||||
/// One choice in an [AppOverflowMenu].
|
||||
class AppMenuAction<T> {
|
||||
const AppMenuAction({
|
||||
@@ -15,21 +12,19 @@ class AppMenuAction<T> {
|
||||
final T value;
|
||||
final String label;
|
||||
|
||||
/// Placed on the menu item (Material) or the sheet action (Cupertino), so a
|
||||
/// test finds the same item on both hosts.
|
||||
/// Placed on the menu item so tests can find the same item.
|
||||
final Key? key;
|
||||
|
||||
/// Shown in the destructive colour on Cupertino's action sheet.
|
||||
// Kept for callers that distinguish destructive actions in their data model;
|
||||
// Material PopupMenuItem does not apply a separate action-sheet treatment.
|
||||
final bool destructive;
|
||||
}
|
||||
|
||||
/// The app's one row/header overflow control: the host's "more" icon that
|
||||
/// opens the row's secondary actions.
|
||||
///
|
||||
/// Material shows a [PopupMenuButton] with [Icons.more_vert]; Cupertino shows
|
||||
/// a [CupertinoButton] with [CupertinoIcons.ellipsis] that opens a
|
||||
/// [CupertinoActionSheet] (with Cancel). Every list row and the run header use
|
||||
/// this, so the overflow icon reads the same everywhere on a host.
|
||||
/// Shows a [PopupMenuButton] with [Icons.more_vert]. Every list row and the run
|
||||
/// header use this, so overflow actions are anchored to their button.
|
||||
class AppOverflowMenu<T> extends StatelessWidget {
|
||||
const AppOverflowMenu({
|
||||
super.key,
|
||||
@@ -38,81 +33,44 @@ class AppOverflowMenu<T> extends StatelessWidget {
|
||||
this.label = 'More actions',
|
||||
this.sheetTitle,
|
||||
this.enabled = true,
|
||||
this.cupertino,
|
||||
});
|
||||
|
||||
final List<AppMenuAction<T>> actions;
|
||||
|
||||
/// Called with the picked value once the menu or sheet has closed.
|
||||
/// Called with the picked value once the menu has closed.
|
||||
final void Function(BuildContext context, T value) onSelected;
|
||||
|
||||
/// Tooltip (Material) and accessible label (both hosts).
|
||||
/// Tooltip and accessible label.
|
||||
final String label;
|
||||
|
||||
/// The Cupertino sheet's title, usually the row's name.
|
||||
/// Retained for source compatibility; Material menus do not show a title.
|
||||
final String? sheetTitle;
|
||||
|
||||
final bool enabled;
|
||||
|
||||
/// Overrides the host detection (some features pick a style per platform).
|
||||
final bool? cupertino;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (actions.isEmpty) return const SizedBox.shrink();
|
||||
if (!(cupertino ?? usesCupertinoHost(context))) {
|
||||
return PopupMenuButton<T>(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
tooltip: label,
|
||||
enabled: enabled,
|
||||
onSelected: (value) => onSelected(context, value),
|
||||
itemBuilder: (_) => [
|
||||
for (final action in actions)
|
||||
PopupMenuItem<T>(
|
||||
key: action.key,
|
||||
value: action.value,
|
||||
child: Text(action.label),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
// Its own node, so a row's merged label never swallows the button.
|
||||
return Semantics(
|
||||
container: true,
|
||||
button: true,
|
||||
enabled: enabled,
|
||||
label: label,
|
||||
excludeSemantics: true,
|
||||
child: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
minimumSize: const Size.square(kMinInteractiveDimensionCupertino),
|
||||
onPressed: enabled ? () => _showSheet(context) : null,
|
||||
child: const Icon(CupertinoIcons.ellipsis),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _showSheet(BuildContext context) async {
|
||||
final picked = await showCupertinoModalPopup<T>(
|
||||
return Localizations.override(
|
||||
context: context,
|
||||
builder: (sheet) => CupertinoActionSheet(
|
||||
title: sheetTitle == null ? null : Text(sheetTitle!),
|
||||
actions: [
|
||||
for (final action in actions)
|
||||
CupertinoActionSheetAction(
|
||||
key: action.key,
|
||||
isDestructiveAction: action.destructive,
|
||||
onPressed: () => Navigator.of(sheet).pop(action.value),
|
||||
child: Text(action.label),
|
||||
),
|
||||
],
|
||||
cancelButton: CupertinoActionSheetAction(
|
||||
isDefaultAction: true,
|
||||
onPressed: () => Navigator.of(sheet).pop(),
|
||||
child: const Text('Cancel'),
|
||||
delegates: const [DefaultMaterialLocalizations.delegate],
|
||||
child: Material(
|
||||
type: MaterialType.transparency,
|
||||
child: PopupMenuButton<T>(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
tooltip: label,
|
||||
enabled: enabled,
|
||||
onSelected: (value) => onSelected(context, value),
|
||||
itemBuilder: (_) => [
|
||||
for (final action in actions)
|
||||
PopupMenuItem<T>(
|
||||
key: action.key,
|
||||
value: action.value,
|
||||
child: Text(action.label),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
if (picked != null && context.mounted) onSelected(context, picked);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user