434 lines
12 KiB
Dart
434 lines
12 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import 'run_detail_content.dart';
|
|
import 'run_detail_summary_fields.dart';
|
|
import 'run_detail_visit_facts.dart';
|
|
import '../../../ui/text/monospace.dart';
|
|
|
|
/// The Summary tab: the run's identity, the recorded facts as key/value rows,
|
|
/// the stored original prompt with its copy control and the collapsible Input
|
|
/// and Output sections.
|
|
///
|
|
/// The web run detail has no usage block, so no metrics are drawn here. A fact
|
|
/// the server did not record is omitted rather than shown as an invented or
|
|
/// `Unavailable` row; only the Input/Output empty sentences remain, and only
|
|
/// when that section recorded nothing.
|
|
Widget runDetailSummaryTab({
|
|
required BuildContext context,
|
|
required JsonMap run,
|
|
required bool cupertino,
|
|
required bool copying,
|
|
required String? copyStatus,
|
|
required VoidCallback onCopy,
|
|
ExpansibleController? inputController,
|
|
ExpansibleController? outputController,
|
|
}) {
|
|
final rows = detailSummaryRows(run);
|
|
final identity = detailSummaryIdentity(run);
|
|
final prompt = detailPrompt(run);
|
|
if (cupertino) {
|
|
return ListView(
|
|
key: const Key('run-detail-tab-body-summary'),
|
|
children: [
|
|
_cupertinoIdentity(context, identity),
|
|
if (rows.any((row) => !row.block))
|
|
CupertinoListSection.insetGrouped(
|
|
children: [
|
|
for (final row in rows.where((row) => !row.block))
|
|
_cupertinoRow(context, row),
|
|
],
|
|
),
|
|
for (final row in rows.where((row) => row.block))
|
|
CupertinoListSection.insetGrouped(
|
|
children: [_cupertinoBlock(context, row)],
|
|
),
|
|
if (prompt != null)
|
|
_cupertinoPrompt(
|
|
context,
|
|
prompt: prompt,
|
|
copying: copying,
|
|
copyStatus: copyStatus,
|
|
onCopy: onCopy,
|
|
),
|
|
_cupertinoFieldSection(
|
|
context,
|
|
key: 'run-detail-summary-input',
|
|
title: 'Input',
|
|
value: run['input'],
|
|
empty: visitEmptyInput,
|
|
controller: inputController,
|
|
),
|
|
_cupertinoFieldSection(
|
|
context,
|
|
key: 'run-detail-summary-output',
|
|
title: 'Output',
|
|
value: run['output'],
|
|
empty: visitEmptyOutput,
|
|
controller: outputController,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
final theme = Theme.of(context);
|
|
return ListView(
|
|
key: const Key('run-detail-tab-body-summary'),
|
|
padding: const EdgeInsets.only(bottom: 16),
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
|
|
child: Text(
|
|
identity,
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
),
|
|
for (final row in rows)
|
|
row.block ? _materialBlock(context, row) : _materialRow(context, row),
|
|
if (prompt != null)
|
|
_materialPrompt(
|
|
context,
|
|
prompt: prompt,
|
|
copying: copying,
|
|
copyStatus: copyStatus,
|
|
onCopy: onCopy,
|
|
),
|
|
_materialFieldSection(
|
|
context,
|
|
key: 'run-detail-summary-input',
|
|
title: 'Input',
|
|
value: run['input'],
|
|
empty: visitEmptyInput,
|
|
controller: inputController,
|
|
),
|
|
_materialFieldSection(
|
|
context,
|
|
key: 'run-detail-summary-output',
|
|
title: 'Output',
|
|
value: run['output'],
|
|
empty: visitEmptyOutput,
|
|
controller: outputController,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
/// One recorded Input or Output field as its own tab, used by a visit pane.
|
|
Widget runDetailFieldTab({
|
|
required String tabKey,
|
|
required dynamic value,
|
|
required String empty,
|
|
required bool cupertino,
|
|
}) {
|
|
final text = detailEmpty(value) ? empty : detailJson(value);
|
|
if (cupertino) {
|
|
return ListView(
|
|
key: Key('run-detail-tab-body-$tabKey'),
|
|
children: [
|
|
CupertinoListSection.insetGrouped(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: _CupertinoSelectableText(text),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
return ListView(
|
|
key: Key('run-detail-tab-body-$tabKey'),
|
|
padding: const EdgeInsets.all(16),
|
|
children: [SelectableText(text)],
|
|
);
|
|
}
|
|
|
|
// --- Material --------------------------------------------------------------
|
|
|
|
Widget _materialRow(BuildContext context, DetailSummaryRow row) {
|
|
final theme = Theme.of(context);
|
|
final base = theme.textTheme.bodyMedium;
|
|
return ListTile(
|
|
key: ValueKey('run-detail-summary-${_slug(row.label)}'),
|
|
title: Text(
|
|
row.label,
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
subtitle: SelectableText(
|
|
row.value,
|
|
style: row.monospace
|
|
? base?.copyWith(fontFamily: appMonospaceFamily)
|
|
: base,
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _materialBlock(BuildContext context, DetailSummaryRow row) {
|
|
final theme = Theme.of(context);
|
|
return Padding(
|
|
key: ValueKey('run-detail-summary-${_slug(row.label)}'),
|
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
row.label,
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: theme.colorScheme.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: SelectableText(
|
|
row.value,
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
fontFamily: appMonospaceFamily,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _materialFieldSection(
|
|
BuildContext context, {
|
|
required String key,
|
|
required String title,
|
|
required dynamic value,
|
|
required String empty,
|
|
ExpansibleController? controller,
|
|
}) {
|
|
return ExpansionTile(
|
|
key: ValueKey(key),
|
|
controller: controller,
|
|
title: Text(title),
|
|
expandedCrossAxisAlignment: CrossAxisAlignment.start,
|
|
childrenPadding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
|
|
children: [SelectableText(detailEmpty(value) ? empty : detailJson(value))],
|
|
);
|
|
}
|
|
|
|
Widget _materialPrompt(
|
|
BuildContext context, {
|
|
required String prompt,
|
|
required bool copying,
|
|
required String? copyStatus,
|
|
required VoidCallback onCopy,
|
|
}) {
|
|
final theme = Theme.of(context);
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(top: 12),
|
|
child: Text(
|
|
'Original prompt',
|
|
style: theme.textTheme.titleMedium,
|
|
),
|
|
),
|
|
),
|
|
IconButton(
|
|
tooltip: 'Copy prompt',
|
|
onPressed: copying ? null : onCopy,
|
|
icon: const Icon(Icons.copy),
|
|
),
|
|
],
|
|
),
|
|
SelectableText(prompt),
|
|
if (copyStatus != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 4),
|
|
child: Semantics(liveRegion: true, child: Text(copyStatus)),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// --- Cupertino -------------------------------------------------------------
|
|
|
|
Widget _cupertinoIdentity(BuildContext context, String identity) {
|
|
final theme = CupertinoTheme.of(context);
|
|
return Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 8),
|
|
child: Text(
|
|
identity,
|
|
style: theme.textTheme.tabLabelTextStyle.copyWith(
|
|
color: CupertinoColors.secondaryLabel.resolveFrom(context),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _cupertinoRow(BuildContext context, DetailSummaryRow row) {
|
|
final style = CupertinoTheme.of(context).textTheme.textStyle;
|
|
return CupertinoListTile(
|
|
key: ValueKey('run-detail-summary-${_slug(row.label)}'),
|
|
title: Text(row.label),
|
|
subtitle: Text(
|
|
row.value,
|
|
style: row.monospace
|
|
? style.copyWith(fontFamily: appMonospaceFamily)
|
|
: null,
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _cupertinoBlock(BuildContext context, DetailSummaryRow row) {
|
|
final theme = CupertinoTheme.of(context);
|
|
return Padding(
|
|
key: ValueKey('run-detail-summary-${_slug(row.label)}'),
|
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 12),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
row.label,
|
|
style: theme.textTheme.tabLabelTextStyle.copyWith(
|
|
color: CupertinoColors.secondaryLabel.resolveFrom(context),
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: CupertinoColors.tertiarySystemFill.resolveFrom(context),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Text(
|
|
row.value,
|
|
style: theme.textTheme.textStyle.copyWith(
|
|
fontFamily: appMonospaceFamily,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _cupertinoFieldSection(
|
|
BuildContext context, {
|
|
required String key,
|
|
required String title,
|
|
required dynamic value,
|
|
required String empty,
|
|
ExpansibleController? controller,
|
|
}) {
|
|
return CupertinoListSection.insetGrouped(
|
|
key: ValueKey(key),
|
|
children: [
|
|
CupertinoExpansionTile(
|
|
title: Text(title),
|
|
controller: controller,
|
|
child: Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
|
|
child: Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: _CupertinoSelectableText(
|
|
detailEmpty(value) ? empty : detailJson(value),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _cupertinoPrompt(
|
|
BuildContext context, {
|
|
required String prompt,
|
|
required bool copying,
|
|
required String? copyStatus,
|
|
required VoidCallback onCopy,
|
|
}) {
|
|
final theme = CupertinoTheme.of(context);
|
|
return Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 16, 16, 0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Wrap(
|
|
alignment: WrapAlignment.spaceBetween,
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
spacing: 8,
|
|
runSpacing: 4,
|
|
children: [
|
|
Text('Original prompt', style: theme.textTheme.navTitleTextStyle),
|
|
CupertinoButton(
|
|
padding: EdgeInsets.zero,
|
|
onPressed: copying ? null : onCopy,
|
|
child: const Text('Copy prompt'),
|
|
),
|
|
],
|
|
),
|
|
_CupertinoSelectableText(prompt),
|
|
if (copyStatus != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 4),
|
|
child: Semantics(liveRegion: true, child: Text(copyStatus)),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
String _slug(String label) => label.toLowerCase().replaceAll(' ', '-');
|
|
|
|
/// A read-only Cupertino text control: plain, selectable text without a
|
|
/// Material dependency, while keeping native selection and copy affordances.
|
|
class _CupertinoSelectableText extends StatefulWidget {
|
|
const _CupertinoSelectableText(this.text);
|
|
final String text;
|
|
|
|
@override
|
|
State<_CupertinoSelectableText> createState() =>
|
|
_CupertinoSelectableTextState();
|
|
}
|
|
|
|
class _CupertinoSelectableTextState extends State<_CupertinoSelectableText> {
|
|
late final TextEditingController _controller = TextEditingController(
|
|
text: widget.text,
|
|
);
|
|
|
|
@override
|
|
void didUpdateWidget(_CupertinoSelectableText oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (widget.text != oldWidget.text) _controller.text = widget.text;
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => CupertinoTextField(
|
|
controller: _controller,
|
|
readOnly: true,
|
|
maxLines: null,
|
|
padding: EdgeInsets.zero,
|
|
decoration: const BoxDecoration(),
|
|
style: CupertinoTheme.of(context).textTheme.textStyle,
|
|
);
|
|
}
|