0dc805ae0e
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>
228 lines
6.1 KiB
Dart
228 lines
6.1 KiB
Dart
import '../../../../ui/adaptive/segmented_bar_overflow.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class ChatBarAction extends StatelessWidget implements SegmentedOverflowable {
|
|
const ChatBarAction({
|
|
super.key,
|
|
required this.label,
|
|
required this.onPressed,
|
|
required this.materialIcon,
|
|
this.identifier,
|
|
this.destructive = false,
|
|
this.subtitle,
|
|
});
|
|
|
|
final String label;
|
|
|
|
/// A short second line the More menu shows under [label] (the account the
|
|
/// action acts on); the bar's icon button adds it to its tooltip.
|
|
final String? subtitle;
|
|
final VoidCallback onPressed;
|
|
final IconData materialIcon;
|
|
|
|
final String? identifier;
|
|
|
|
/// Closes or removes something; menus list it last, in the error colour.
|
|
final bool destructive;
|
|
|
|
/// A narrow bar moves it into its More menu, under the bar's host's icon.
|
|
@override
|
|
SegmentedOverflowEntry get overflowEntry => SegmentedOverflowEntry(
|
|
label: label,
|
|
icon: materialIcon,
|
|
onPressed: onPressed,
|
|
destructive: destructive,
|
|
subtitle: subtitle,
|
|
);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final subtitle = this.subtitle;
|
|
return Semantics(
|
|
identifier: identifier,
|
|
child: IconButton(
|
|
tooltip: subtitle == null || subtitle.isEmpty
|
|
? label
|
|
: '$label\n$subtitle',
|
|
onPressed: onPressed,
|
|
icon: Icon(materialIcon),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// The chat toolbar's one primary create action, labelled as on the web
|
|
/// (`+ New chat`), not an unlabelled glyph.
|
|
class ChatNewChatButton extends StatelessWidget {
|
|
const ChatNewChatButton({super.key, required this.onPressed});
|
|
|
|
final VoidCallback onPressed;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FilledButton.icon(
|
|
onPressed: onPressed,
|
|
icon: const Icon(Icons.add),
|
|
label: const Text('New chat'),
|
|
);
|
|
}
|
|
}
|
|
|
|
class ChatSearchField extends StatelessWidget {
|
|
const ChatSearchField({
|
|
super.key,
|
|
required this.controller,
|
|
required this.onChanged,
|
|
this.trailing = const [],
|
|
this.autofocus = false,
|
|
});
|
|
|
|
final TextEditingController controller;
|
|
final ValueChanged<String> onChanged;
|
|
final bool autofocus;
|
|
|
|
/// Actions on the search row's trailing edge, as the web's chat toolbar
|
|
/// keeps New chat beside its search input.
|
|
final List<Widget> trailing;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final field = TextField(
|
|
controller: controller,
|
|
onChanged: onChanged,
|
|
autofocus: autofocus,
|
|
decoration: const InputDecoration(
|
|
prefixIcon: Icon(Icons.search),
|
|
labelText: 'Search chats',
|
|
),
|
|
);
|
|
return Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: trailing.isEmpty
|
|
? field
|
|
: Row(
|
|
children: [
|
|
Expanded(child: field),
|
|
for (final action in trailing) ...[
|
|
const SizedBox(width: 8),
|
|
action,
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// A row action's refusal, shown at full width beneath its tile.
|
|
///
|
|
/// It must not sit in a list tile's subtitle slot: that slot forces every
|
|
/// paragraph to one ellipsised line, which cut the server's reason down to its
|
|
/// first few words. Full width also stops a long refusal from turning a single
|
|
/// Material row into a column taller than the viewport.
|
|
class ChatRowError extends StatelessWidget {
|
|
const ChatRowError({
|
|
super.key,
|
|
required this.message,
|
|
this.messageKey,
|
|
this.onDismiss,
|
|
});
|
|
|
|
final String message;
|
|
|
|
/// Clears this refusal; its control reads the web report's `OK`.
|
|
final VoidCallback? onDismiss;
|
|
|
|
/// Key placed on the message paragraph itself, so a test can assert that the
|
|
/// rendered text did not exceed its line limit.
|
|
final Key? messageKey;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final style = TextStyle(color: Theme.of(context).colorScheme.error);
|
|
return Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 12),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: DefaultTextStyle.merge(
|
|
style: style,
|
|
child: Text(message, key: messageKey),
|
|
),
|
|
),
|
|
if (onDismiss != null)
|
|
Semantics(
|
|
button: true,
|
|
label: 'Dismiss refusal',
|
|
excludeSemantics: true,
|
|
child: TextButton(onPressed: onDismiss, child: const Text('OK')),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class ChatErrorNotice extends StatelessWidget {
|
|
const ChatErrorNotice({
|
|
super.key,
|
|
required this.message,
|
|
required this.onRetry,
|
|
});
|
|
|
|
final String message;
|
|
final VoidCallback onRetry;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialBanner(
|
|
content: Text(message),
|
|
actions: [TextButton(onPressed: onRetry, child: const Text('Retry'))],
|
|
);
|
|
}
|
|
}
|
|
|
|
class ChatLoadingIndicator extends StatelessWidget {
|
|
const ChatLoadingIndicator({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
}
|
|
|
|
/// One-row report after hiding a session on this device, with its Undo.
|
|
///
|
|
/// The screen floats this over the list like the web's fixed report, so a long
|
|
/// message can never push the list out of the body's column.
|
|
class ChatUndoBar extends StatelessWidget {
|
|
const ChatUndoBar({super.key, required this.message, required this.onUndo});
|
|
|
|
final String message;
|
|
final VoidCallback onUndo;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final content = Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: DefaultTextStyle.merge(
|
|
style: DefaultTextStyle.of(context).style,
|
|
child: Text(message),
|
|
),
|
|
),
|
|
TextButton(onPressed: onUndo, child: const Text('Undo')),
|
|
],
|
|
),
|
|
);
|
|
return Material(
|
|
elevation: 3,
|
|
borderRadius: BorderRadius.circular(8),
|
|
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
|
child: content,
|
|
);
|
|
}
|
|
}
|