96de9f5bea
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.
223 lines
7.2 KiB
Dart
223 lines
7.2 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
import '../../../ui/text/monospace.dart';
|
|
import '../domain/chat_session_handoff.dart';
|
|
import '../ui/sessions/chat_create_fields.dart';
|
|
import 'chat_export_controller.dart';
|
|
|
|
/// The info sheet's "Session" section: the harness's native session id with a
|
|
/// copy control, the harness and the working directory, the verified terminal
|
|
/// command that resumes the session, and the export actions.
|
|
///
|
|
/// `cupertino` is kept for existing callers; the section is always Material.
|
|
class ChatSessionSection extends StatefulWidget {
|
|
const ChatSessionSection({
|
|
super.key,
|
|
required this.handoff,
|
|
required this.exporter,
|
|
required this.cupertino,
|
|
});
|
|
|
|
final ChatSessionHandoff handoff;
|
|
final ChatExportController exporter;
|
|
final bool cupertino;
|
|
|
|
@override
|
|
State<ChatSessionSection> createState() => _ChatSessionSectionState();
|
|
}
|
|
|
|
class _ChatSessionSectionState extends State<ChatSessionSection> {
|
|
/// Which copy control last succeeded, shown as "Copied" for a moment.
|
|
String? _copied;
|
|
Timer? _reset;
|
|
|
|
@override
|
|
void dispose() {
|
|
_reset?.cancel();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> _copy(String key, String text) async {
|
|
await Clipboard.setData(ClipboardData(text: text));
|
|
if (!mounted) return;
|
|
setState(() => _copied = key);
|
|
_reset?.cancel();
|
|
_reset = Timer(const Duration(seconds: 2), () {
|
|
if (mounted) setState(() => _copied = null);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final handoff = widget.handoff;
|
|
final secondary = Theme.of(context).colorScheme.onSurfaceVariant;
|
|
final body = Theme.of(context).textTheme.bodyLarge;
|
|
final title = Theme.of(context).textTheme.titleSmall;
|
|
final label = Theme.of(
|
|
context,
|
|
).textTheme.bodySmall?.copyWith(color: secondary);
|
|
final mono = body?.copyWith(fontFamily: appMonospaceFamily);
|
|
final muted = body?.copyWith(color: secondary);
|
|
|
|
Widget fact(String key, String name, String value, {bool code = false}) {
|
|
final known = value.isNotEmpty;
|
|
return Padding(
|
|
key: Key('chat-session-$key'),
|
|
padding: const EdgeInsets.only(top: 8),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(name, style: label),
|
|
Text(
|
|
known ? value : 'Unavailable',
|
|
key: Key('chat-session-value-$key'),
|
|
style: !known ? muted : (code ? mono : body),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
return AnimatedBuilder(
|
|
animation: widget.exporter,
|
|
builder: (context, _) {
|
|
final exporter = widget.exporter;
|
|
final status = exporter.status;
|
|
return Padding(
|
|
key: const Key('chat-session-section'),
|
|
padding: const EdgeInsetsDirectional.fromSTEB(24, 12, 24, 6),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Text('Session', style: title),
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
Expanded(
|
|
child: fact('id', 'Session ID', handoff.id, code: true),
|
|
),
|
|
_ActionButton(
|
|
key: const Key('chat-session-copy-id'),
|
|
label: _copied == 'id' ? 'Copied' : 'Copy',
|
|
semanticsLabel: _copied == 'id'
|
|
? 'Copied'
|
|
: 'Copy session ID',
|
|
icon: _copied == 'id' ? Icons.check : Icons.copy_outlined,
|
|
onPressed: handoff.id.isEmpty
|
|
? null
|
|
: () => _copy('id', handoff.id),
|
|
),
|
|
],
|
|
),
|
|
fact('harness', 'Harness', chatBackendLabel(handoff.backend)),
|
|
fact('directory', 'Directory', handoff.directory, code: true),
|
|
if (handoff.resumeCommand.isNotEmpty)
|
|
fact(
|
|
'resume',
|
|
'Resume in a terminal',
|
|
handoff.resumeCommand,
|
|
code: true,
|
|
),
|
|
const SizedBox(height: 8),
|
|
Wrap(
|
|
spacing: 8,
|
|
runSpacing: 4,
|
|
children: [
|
|
if (handoff.resumeCommand.isNotEmpty)
|
|
_ActionButton(
|
|
key: const Key('chat-session-copy-resume'),
|
|
label: _copied == 'resume'
|
|
? 'Copied'
|
|
: 'Copy resume command',
|
|
icon: _copied == 'resume' ? Icons.check : Icons.terminal,
|
|
onPressed: () => _copy('resume', handoff.resumeCommand),
|
|
),
|
|
_exportButton(
|
|
ChatExportFormat.markdown,
|
|
'Export conversation',
|
|
Icons.ios_share,
|
|
),
|
|
_exportButton(
|
|
ChatExportFormat.json,
|
|
'Export JSON',
|
|
Icons.data_object,
|
|
),
|
|
if (handoff.nativeExport)
|
|
_exportButton(
|
|
ChatExportFormat.native,
|
|
'Export native session',
|
|
Icons.description_outlined,
|
|
),
|
|
],
|
|
),
|
|
if (status != null && status.isNotEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 6),
|
|
child: Semantics(
|
|
liveRegion: true,
|
|
child: Text(
|
|
status,
|
|
key: const Key('chat-session-export-status'),
|
|
style: label,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _exportButton(ChatExportFormat format, String label, IconData icon) {
|
|
final exporter = widget.exporter;
|
|
return _ActionButton(
|
|
key: Key('chat-session-export-${format.wire}'),
|
|
label: label,
|
|
icon: icon,
|
|
busy: exporter.active == format,
|
|
onPressed: exporter.busy ? null : () => exporter.export(format),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// A standard text button with a leading icon, in the host's style.
|
|
class _ActionButton extends StatelessWidget {
|
|
const _ActionButton({
|
|
super.key,
|
|
required this.label,
|
|
required this.icon,
|
|
required this.onPressed,
|
|
this.semanticsLabel,
|
|
this.busy = false,
|
|
});
|
|
|
|
final String label;
|
|
final String? semanticsLabel;
|
|
final IconData icon;
|
|
final VoidCallback? onPressed;
|
|
final bool busy;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final Widget leading = busy
|
|
? const SizedBox.square(
|
|
dimension: 18,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
)
|
|
: Icon(icon, size: 18);
|
|
final child = Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
leading,
|
|
const SizedBox(width: 6),
|
|
Flexible(child: Text(label, semanticsLabel: semanticsLabel)),
|
|
],
|
|
);
|
|
return TextButton(onPressed: onPressed, child: child);
|
|
}
|
|
}
|