4bc99f490b
The transcript listener read the lazily built _controller while _attach was still building it (load() notifies synchronously), so it built another controller, recursively, until the test process ran out of memory.
105 lines
3.3 KiB
Dart
105 lines
3.3 KiB
Dart
import 'package:flutter/cupertino.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.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.
|
|
class ChatDeliveryIndicator extends StatelessWidget {
|
|
const ChatDeliveryIndicator({
|
|
super.key,
|
|
required this.state,
|
|
required this.cupertino,
|
|
this.onRetry,
|
|
this.onEdit,
|
|
this.editLabel = 'Edit',
|
|
});
|
|
|
|
final ChatDelivery state;
|
|
final bool cupertino;
|
|
final VoidCallback? onRetry;
|
|
final VoidCallback? onEdit;
|
|
final String editLabel;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final failed = state == ChatDelivery.failed;
|
|
final color = failed
|
|
? (cupertino
|
|
? CupertinoColors.systemRed.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.error)
|
|
: (cupertino
|
|
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
|
: 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),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
IconData get _icon => switch (state) {
|
|
ChatDelivery.sending => cupertino ? CupertinoIcons.clock : Icons.schedule,
|
|
ChatDelivery.sent => cupertino ? CupertinoIcons.checkmark : Icons.done,
|
|
ChatDelivery.queued =>
|
|
cupertino ? CupertinoIcons.hourglass : Icons.hourglass_empty,
|
|
ChatDelivery.failed =>
|
|
cupertino ? CupertinoIcons.exclamationmark_circle : Icons.error_outline,
|
|
};
|
|
|
|
Widget _action(
|
|
String key,
|
|
String text,
|
|
VoidCallback onPressed,
|
|
TextStyle style,
|
|
) {
|
|
if (cupertino) {
|
|
return CupertinoButton(
|
|
key: Key(key),
|
|
padding: const EdgeInsets.symmetric(horizontal: 6),
|
|
minimumSize: Size.zero,
|
|
onPressed: onPressed,
|
|
child: Text(text, style: style.copyWith(fontWeight: FontWeight.w600)),
|
|
);
|
|
}
|
|
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),
|
|
);
|
|
}
|
|
}
|