42a2378ecb
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.
77 lines
2.1 KiB
Dart
77 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
/// One choice in an [AppOverflowMenu].
|
|
class AppMenuAction<T> {
|
|
const AppMenuAction({
|
|
required this.value,
|
|
required this.label,
|
|
this.key,
|
|
this.destructive = false,
|
|
});
|
|
|
|
final T value;
|
|
final String label;
|
|
|
|
/// Placed on the menu item so tests can find the same item.
|
|
final Key? key;
|
|
|
|
// 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.
|
|
///
|
|
/// 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,
|
|
required this.actions,
|
|
required this.onSelected,
|
|
this.label = 'More actions',
|
|
this.sheetTitle,
|
|
this.enabled = true,
|
|
});
|
|
|
|
final List<AppMenuAction<T>> actions;
|
|
|
|
/// Called with the picked value once the menu has closed.
|
|
final void Function(BuildContext context, T value) onSelected;
|
|
|
|
/// Tooltip and accessible label.
|
|
final String label;
|
|
|
|
/// Retained for source compatibility; Material menus do not show a title.
|
|
final String? sheetTitle;
|
|
|
|
final bool enabled;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (actions.isEmpty) return const SizedBox.shrink();
|
|
return Localizations.override(
|
|
context: context,
|
|
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),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|