Files
pipelines/app/lib/ui/adaptive/app_action_sheet.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

183 lines
5.4 KiB
Dart

import 'package:flutter/material.dart';
/// One action in an [showAppActionSheet] sheet.
class AppSheetAction {
const AppSheetAction({
required this.label,
this.icon,
this.onSelected,
this.destructive = false,
this.enabled = true,
this.selected = false,
this.choices = const [],
this.key,
this.subtitle,
});
final String label;
final IconData? icon;
/// A short second line under [label].
final String? subtitle;
/// Runs once the sheet has closed. Null (with no [choices]) disables it.
final VoidCallback? onSelected;
/// Shown last, after a divider, in the theme's error colour.
final bool destructive;
final bool enabled;
/// Marks the current choice in a [choices] list.
final bool selected;
/// Choices offered on a second sheet (a sort order) instead of [onSelected].
final List<AppSheetAction> choices;
/// Placed on the row so tests can find it.
final Key? key;
}
/// A phone's menu: a modal bottom sheet with a header naming what the actions
/// apply to ([title], [subtitle]) and one full-width row per action, each with
/// its icon. Destructive actions come last, after a divider, in the error
/// colour. The chosen action runs after the sheet has closed.
Future<void> showAppActionSheet(
BuildContext context, {
String? title,
String? subtitle,
required List<AppSheetAction> actions,
}) async {
final chosen = await showModalBottomSheet<AppSheetAction>(
context: context,
useRootNavigator: true,
showDragHandle: true,
isScrollControlled: true,
useSafeArea: true,
builder: (sheet) =>
_ActionSheet(title: title, subtitle: subtitle, actions: actions),
);
if (chosen == null) return;
if (chosen.choices.isNotEmpty) {
if (!context.mounted) return;
return showAppActionSheet(
context,
title: chosen.label,
actions: chosen.choices,
);
}
chosen.onSelected?.call();
}
class _ActionSheet extends StatelessWidget {
const _ActionSheet({
required this.title,
required this.subtitle,
required this.actions,
});
final String? title;
final String? subtitle;
final List<AppSheetAction> actions;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final regular = [
for (final action in actions)
if (!action.destructive) action,
];
final destructive = [
for (final action in actions)
if (action.destructive) action,
];
final hasTitle = title != null && title!.trim().isNotEmpty;
return SafeArea(
top: false,
child: SingleChildScrollView(
padding: const EdgeInsets.only(bottom: 8),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (hasTitle) ...[
Padding(
padding: const EdgeInsets.fromLTRB(24, 0, 24, 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title!,
style: theme.textTheme.titleMedium,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
if (subtitle != null && subtitle!.trim().isNotEmpty) ...[
const SizedBox(height: 2),
Text(
subtitle!,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
],
),
),
const Divider(height: 1),
],
const SizedBox(height: 8),
for (final action in regular) _ActionRow(action: action),
if (destructive.isNotEmpty) ...[
if (regular.isNotEmpty)
const Divider(height: 17, indent: 24, endIndent: 24),
for (final action in destructive) _ActionRow(action: action),
],
],
),
),
);
}
}
class _ActionRow extends StatelessWidget {
const _ActionRow({required this.action});
final AppSheetAction action;
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final enabled =
action.enabled &&
(action.onSelected != null || action.choices.isNotEmpty);
final color = action.destructive ? scheme.error : null;
return ListTile(
key: action.key,
enabled: enabled,
minTileHeight: 56,
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
leading: action.icon == null
? null
: Icon(action.icon, color: enabled ? color : null),
iconColor: scheme.onSurfaceVariant,
title: Text(
action.label,
style: color == null || !enabled ? null : TextStyle(color: color),
),
subtitle: switch (action.subtitle) {
final subtitle? when subtitle.isNotEmpty => Text(subtitle),
_ => null,
},
trailing: action.choices.isNotEmpty
? const Icon(Icons.chevron_right)
: action.selected
? Icon(Icons.check, color: scheme.primary)
: null,
selected: action.selected,
onTap: enabled ? () => Navigator.of(context).pop(action) : null,
);
}
}