Files
pipelines/app/lib/features/chat/conversation/chat_delivery_indicator.dart
T
alan 96de9f5bea Remove Cupertino chat conversation branches
Keep the Material-only conversation implementation while preserving public Cupertino parameters for callers. Narrow affected tests to Material hosts so the dead platform paths are no longer exercised.
2026-11-11 13:11:05 +00:00

98 lines
3.1 KiB
Dart

import 'package:flutter/material.dart';
import 'chat_deliveries.dart';
/// The words each delivery state reads as, beside its icon.
String chatDeliveryLabel(ChatDelivery state) => switch (state) {
ChatDelivery.sending => 'Sending…',
ChatDelivery.sent => 'Sent',
ChatDelivery.queued => 'Queued',
ChatDelivery.steered => 'Delivered to the running reply',
ChatDelivery.failed => 'Not sent',
};
/// A small muted line under the operator's own bubble saying whether the
/// server has the message. "Not sent" takes the error colour and offers the
/// native Retry (same operation id) and Edit (back into the composer) — or
/// Discard when the stored intent can no longer be sent as it was. "Queued"
/// offers Remove, which takes the message off the server's queue.
class ChatDeliveryIndicator extends StatelessWidget {
const ChatDeliveryIndicator({
super.key,
required this.state,
required this.cupertino,
this.onRetry,
this.onEdit,
this.editLabel = 'Edit',
this.onRemove,
});
final ChatDelivery state;
final bool cupertino;
final VoidCallback? onRetry;
final VoidCallback? onEdit;
final String editLabel;
/// Takes a "Queued" message back off the server's queue before it is sent.
final VoidCallback? onRemove;
@override
Widget build(BuildContext context) {
final failed = state == ChatDelivery.failed;
final color = failed
? Theme.of(context).colorScheme.error
: Theme.of(context).colorScheme.onSurfaceVariant;
final style = DefaultTextStyle.of(
context,
).style.merge(TextStyle(fontSize: 12, color: color));
final label = chatDeliveryLabel(state);
return Semantics(
container: true,
label: 'Delivery: $label',
child: Wrap(
key: Key('chat-delivery-${state.name}'),
spacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
ExcludeSemantics(
child: Icon(_icon, size: style.fontSize! + 2, color: color),
),
ExcludeSemantics(child: Text(label, style: style)),
if (failed && onRetry != null)
_action('chat-delivery-retry', 'Retry', onRetry!, style),
if (failed && onEdit != null)
_action('chat-delivery-edit', editLabel, onEdit!, style),
if (state == ChatDelivery.queued && onRemove != null)
_action('chat-delivery-remove', 'Remove', onRemove!, style),
],
),
);
}
IconData get _icon => switch (state) {
ChatDelivery.sending => Icons.schedule,
ChatDelivery.sent => Icons.done,
ChatDelivery.queued => Icons.hourglass_empty,
ChatDelivery.steered => Icons.done,
ChatDelivery.failed => Icons.error_outline,
};
Widget _action(
String key,
String text,
VoidCallback onPressed,
TextStyle style,
) {
return TextButton(
key: Key(key),
style: TextButton.styleFrom(
foregroundColor: style.color,
visualDensity: VisualDensity.compact,
textStyle: style.copyWith(fontWeight: FontWeight.w600),
),
onPressed: onPressed,
child: Text(text),
);
}
}