Files
pipelines/app/lib/ui/layout/app_overflow_menu.dart
T
alan 3ce7f7a5dd Expose pane actions in chat list menu
Share the open chat pane menu choices with session rows so list actions use the same handlers and target the selected chat. Add command routing, pane movement support, and focused coverage for wide and narrow layouts.
2026-11-12 01:17:46 +00:00

94 lines
2.8 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,
this.enabled = true,
});
final T value;
final String label;
/// Placed on the menu item so tests can find the same item.
final Key? key;
/// A disabled item stays listed but cannot be chosen.
final bool enabled;
// 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,
this.actions = const [],
this.actionsBuilder,
required this.onSelected,
this.label = 'More actions',
this.sheetTitle,
this.enabled = true,
this.icon = const Icon(Icons.more_vert),
});
final List<AppMenuAction<T>> actions;
/// When given, supplies the choices each time the menu opens, instead of
/// [actions]; for choices that depend on state read at that moment.
final List<AppMenuAction<T>> Function()? actionsBuilder;
/// 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 (actionsBuilder == null && 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 actionsBuilder?.call() ?? actions)
PopupMenuItem<T>(
key: action.key,
value: action.value,
enabled: action.enabled,
child: Text(action.label),
),
],
),
),
);
}
}