feat(chat): ChatGPT-style transcript and composer
Agent replies sit on the page without a bubble and get a copy control; the operator's turn is a neutral rounded bubble; the composer is one filled pill with +, a borderless field and a round Send, and its placeholder names the chat's folder. Also fixes two picker tests left stale by the native picker.
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// The accessible name of a reply's copy control, and its name just after a
|
||||
/// copy succeeded.
|
||||
const String chatCopyLabel = 'Copy';
|
||||
const String chatCopiedLabel = 'Copied';
|
||||
|
||||
/// An icon-only control beneath a finished reply that puts the reply's text on
|
||||
/// the clipboard. It shows a check for a moment after copying, so the operator
|
||||
/// sees the copy landed without a separate toast.
|
||||
class ChatCopyButton extends StatefulWidget {
|
||||
const ChatCopyButton({
|
||||
super.key,
|
||||
required this.text,
|
||||
required this.cupertino,
|
||||
});
|
||||
|
||||
final String text;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
State<ChatCopyButton> createState() => _ChatCopyButtonState();
|
||||
}
|
||||
|
||||
class _ChatCopyButtonState extends State<ChatCopyButton> {
|
||||
bool _copied = false;
|
||||
Timer? _reset;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_reset?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _copy() async {
|
||||
await Clipboard.setData(ClipboardData(text: widget.text));
|
||||
if (!mounted) return;
|
||||
setState(() => _copied = true);
|
||||
_reset?.cancel();
|
||||
_reset = Timer(const Duration(seconds: 2), () {
|
||||
if (mounted) setState(() => _copied = false);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final label = _copied ? chatCopiedLabel : chatCopyLabel;
|
||||
if (widget.cupertino) {
|
||||
return Semantics(
|
||||
button: true,
|
||||
label: label,
|
||||
excludeSemantics: true,
|
||||
child: CupertinoButton(
|
||||
key: const Key('chat-message-copy'),
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: _copy,
|
||||
child: Icon(
|
||||
_copied ? CupertinoIcons.checkmark : CupertinoIcons.doc_on_doc,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return IconButton(
|
||||
key: const Key('chat-message-copy'),
|
||||
tooltip: label,
|
||||
onPressed: _copy,
|
||||
icon: Icon(_copied ? Icons.check : Icons.copy_outlined),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user