6cacd11c6b
Give the FilesHeader sort control a recognizable Material sort glyph while preserving the default overflow icon for other menus. Add focused widget coverage for sort key and direction behavior.
82 lines
2.3 KiB
Dart
82 lines
2.3 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,
|
|
this.icon = const Icon(Icons.more_vert),
|
|
});
|
|
|
|
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;
|
|
|
|
/// The button glyph. Most callers use the default overflow icon; controls
|
|
/// whose action has a distinct meaning can provide a matching Material icon.
|
|
final Widget icon;
|
|
|
|
@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: icon,
|
|
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),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|