Files
pipelines/app/lib/ui/adaptive/segmented_bar_overflow.dart
T
alan 0dc805ae0e Chat: show the active Claude account in the send tooltip, menu and limit banner
usage.account now carries the email and organization of the account
Claude Code is signed in to (from its initialize account, or the saved
account just switched to), sent at process start and after a switch.
The app shows it as the send tooltip's usage prefix, the Claude account
menu subtitle, the usage-limit banner's status line and the info sheet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 16:33:46 +00:00

198 lines
5.8 KiB
Dart

import 'app_action_sheet.dart';
import 'app_menu_anchor.dart';
import 'app_popups.dart';
import 'package:flutter/material.dart';
/// The key of a [SegmentedBar]'s More button, shown when its actions do not
/// all fit.
const segmentedMoreKey = ValueKey<String>('segmented.more');
/// One choice under a [SegmentedOverflowEntry] (a sort order): a Material submenu.
class SegmentedMenuChoice {
const SegmentedMenuChoice({
required this.label,
required this.onSelected,
this.selected = false,
});
final String label;
final VoidCallback onSelected;
final bool selected;
}
/// How a bar action reads in the bar's More menu once a narrow bar moves it
/// there: its label and icon, and what choosing it does.
class SegmentedOverflowEntry {
const SegmentedOverflowEntry({
required this.label,
required this.icon,
this.onPressed,
this.choices = const [],
this.shortcut,
this.destructive = false,
this.subtitle,
});
final String label;
final IconData icon;
/// A short second line under [label] (the account an entry acts on).
final String? subtitle;
/// Closes or removes something (Close pane): listed last on a phone sheet,
/// after a divider, in the error colour.
final bool destructive;
/// What choosing the entry does; null (with no [choices]) disables it.
final VoidCallback? onPressed;
/// Choices offered under the entry instead of [onPressed].
final List<SegmentedMenuChoice> choices;
/// The keyboard shortcut the Material menu lists beside the entry. It is
/// shown only; the owner handles the keys itself.
final MenuSerializableShortcut? shortcut;
}
/// A bar action the bar may move into its More menu. An action that is not
/// [SegmentedOverflowable] always stays in the bar.
abstract interface class SegmentedOverflowable {
SegmentedOverflowEntry get overflowEntry;
}
/// Marks any bar action as [SegmentedOverflowable]: it draws [child] in the
/// bar and [overflowEntry] in the More menu.
class SegmentedOverflowAction extends StatelessWidget
implements SegmentedOverflowable {
const SegmentedOverflowAction({
super.key,
required this.overflowEntry,
required this.child,
});
@override
final SegmentedOverflowEntry overflowEntry;
final Widget child;
@override
Widget build(BuildContext context) => child;
}
/// The bar's More button: the host's overflow icon at the platform's touch
/// target, opening a Material menu of [entries] on a wide app and a bottom
/// sheet headed by [sheetTitle] on a phone.
class SegmentedMoreButton extends StatelessWidget {
const SegmentedMoreButton({
super.key,
required this.entries,
this.sheetTitle,
this.sheetSubtitle,
});
final List<SegmentedOverflowEntry> entries;
/// The phone sheet's header: what the actions apply to (a chat).
final String? sheetTitle;
final String? sheetSubtitle;
static const String label = 'More actions';
@override
Widget build(BuildContext context) {
if (!usesDesktopPopups(context)) {
return IconButton(
key: segmentedMoreKey,
tooltip: label,
icon: const Icon(Icons.more_vert),
onPressed: () => showAppActionSheet(
context,
title: sheetTitle,
subtitle: sheetSubtitle,
actions: [
for (final entry in entries)
AppSheetAction(
label: entry.label,
subtitle: entry.subtitle,
icon: entry.icon,
onSelected: entry.onPressed,
destructive: entry.destructive,
choices: [
for (final choice in entry.choices)
AppSheetAction(
label: choice.label,
selected: choice.selected,
onSelected: choice.onSelected,
),
],
),
],
),
);
}
return AppMenuAnchor(
menuChildren: [
for (final entry in entries)
if (entry.choices.isEmpty)
MenuItemButton(
leadingIcon: Icon(entry.icon),
onPressed: entry.onPressed,
shortcut: entry.shortcut,
child: _EntryText(entry),
)
else
SubmenuButton(
leadingIcon: Icon(entry.icon),
menuChildren: [
for (final choice in entry.choices)
MenuItemButton(
leadingIcon: Icon(
Icons.check,
color: choice.selected ? null : Colors.transparent,
),
onPressed: choice.onSelected,
child: Semantics(
selected: choice.selected,
child: Text(choice.label),
),
),
],
child: Text(entry.label),
),
],
builder: (context, menu, _) => IconButton(
key: segmentedMoreKey,
tooltip: label,
onPressed: () => menu.isOpen ? menu.close() : menu.open(),
icon: const Icon(Icons.more_vert),
),
);
}
}
/// A menu entry's label, with its subtitle beneath in the muted small style.
class _EntryText extends StatelessWidget {
const _EntryText(this.entry);
final SegmentedOverflowEntry entry;
@override
Widget build(BuildContext context) {
final subtitle = entry.subtitle;
if (subtitle == null || subtitle.isEmpty) return Text(entry.label);
final theme = Theme.of(context);
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(entry.label),
Text(
subtitle,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
],
);
}
}