Files
pipelines/app/lib/ui/layout/app_overflow_menu.dart
T
alan 3c56db37fd Share one list row across runs, pipelines, chat, search and schedules
AppListRow (Material + Cupertino) with avatar, bold title and trailing
time, one muted line, one overflow menu style, inset dividers, selected
and emphasised states and a compact mode. Pipelines get a legible initial
avatar, schedule rows shrink to two lines with Edit/Pause/Delete in an
overflow menu, and the shell chat list scrolls behind the bar.
2026-10-31 04:15:01 +00:00

119 lines
3.6 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/host.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 (Material) or the sheet action (Cupertino), so a
/// test finds the same item on both hosts.
final Key? key;
/// Shown in the destructive colour on Cupertino's action sheet.
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.
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.cupertino,
});
final List<AppMenuAction<T>> actions;
/// Called with the picked value once the menu or sheet has closed.
final void Function(BuildContext context, T value) onSelected;
/// Tooltip (Material) and accessible label (both hosts).
final String label;
/// The Cupertino sheet's title, usually the row's name.
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>(
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'),
),
),
);
if (picked != null && context.mounted) onSelected(context, picked);
}
}