feat(app): render run detail with native Material and Cupertino controls
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../domain/run_models.dart';
|
||||
|
||||
/// One labelled value in the run detail's metrics block.
|
||||
typedef DetailMetric = ({String label, String value});
|
||||
|
||||
/// One recorded visit in the run detail's timeline.
|
||||
typedef DetailVisit = ({String title, String subtitle});
|
||||
|
||||
/// The run's primary label: the stored title, else the pipeline name, and only
|
||||
/// then the numeric identity.
|
||||
String detailTitle(JsonMap run) {
|
||||
final identity = runIdentity(run['title'], run['name']);
|
||||
return identity.label.trim().isEmpty ? 'Run ${run['id']}' : identity.label;
|
||||
}
|
||||
|
||||
String detailPipeline(JsonMap run) {
|
||||
final name = '${run['name'] ?? ''}'.trim();
|
||||
return name.isEmpty ? 'unavailable' : name;
|
||||
}
|
||||
|
||||
/// The original prompt exactly as the server stored it; never trimmed or
|
||||
/// replaced by another field.
|
||||
String? detailPrompt(JsonMap run) {
|
||||
final input = run['input'];
|
||||
return input is Map && input['prompt'] is String
|
||||
? input['prompt'] as String
|
||||
: null;
|
||||
}
|
||||
|
||||
/// Nested input/output shown as formatted, selectable JSON.
|
||||
String detailJson(dynamic value) =>
|
||||
const JsonEncoder.withIndent(' ').convert(value);
|
||||
|
||||
bool detailEmpty(dynamic value) => value is! Map || value.isEmpty;
|
||||
|
||||
/// Reported run metrics. A present zero with a reporting stage count is a real
|
||||
/// zero; a zero without that evidence is unavailable, never a measured zero.
|
||||
List<DetailMetric> detailUsageMetrics(dynamic raw) {
|
||||
if (raw is! Map || raw.isEmpty) return const [];
|
||||
final usage = Map<String, dynamic>.from(raw);
|
||||
final stages = _int(usage['stages']);
|
||||
final tokenStages = _int(usage['tokens_known_stages']) ?? 0;
|
||||
final costStages = _int(usage['cost_known_stages']) ?? 0;
|
||||
final totalTokens = _int(usage['tokens_total']);
|
||||
final splitKnown = usage['split_known'] == true && tokenStages > 0;
|
||||
final rows = <DetailMetric>[
|
||||
if (stages != null) (label: 'Stages', value: '$stages'),
|
||||
(
|
||||
label: 'Total tokens',
|
||||
value: tokenStages == 0 || totalTokens == null
|
||||
? 'Unavailable'
|
||||
: '$totalTokens',
|
||||
),
|
||||
(
|
||||
label: 'Input tokens',
|
||||
value: splitKnown ? '${_int(usage['tokens_in']) ?? 0}' : 'Unavailable',
|
||||
),
|
||||
(
|
||||
label: 'Output tokens',
|
||||
value: splitKnown ? '${_int(usage['tokens_out']) ?? 0}' : 'Unavailable',
|
||||
),
|
||||
(
|
||||
label: 'Reported cost',
|
||||
// cost_usd is omitted by the server when zero, so a known stage count
|
||||
// makes an absent value a real $0.000000 rather than an unknown cost.
|
||||
value: costStages == 0
|
||||
? 'Unavailable'
|
||||
: '\$${((usage['cost_usd'] as num?) ?? 0).toStringAsFixed(6)}',
|
||||
),
|
||||
];
|
||||
if (stages != null && tokenStages < stages) {
|
||||
rows.add((
|
||||
label: 'Token reporting',
|
||||
value: '$tokenStages of $stages stages',
|
||||
));
|
||||
}
|
||||
if (stages != null && costStages < stages) {
|
||||
rows.add((label: 'Cost reporting', value: '$costStages of $stages stages'));
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/// Every recorded visit with its server sequence, in recorded order.
|
||||
List<DetailVisit> detailTimeline(dynamic steps) {
|
||||
if (steps is! List) return const [];
|
||||
return [
|
||||
for (final step in steps.whereType<Map>())
|
||||
(
|
||||
title:
|
||||
'${_text(step['stage'], 'Stage unavailable')} · visit '
|
||||
'${step['sequence'] is num ? (step['sequence'] as num).toInt() : 'unavailable'}',
|
||||
subtitle: _visitSubtitle(step),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
String _visitSubtitle(Map step) {
|
||||
final status = _text(step['status'], 'Status unavailable');
|
||||
final outcome = '${step['outcome'] ?? ''}'.trim();
|
||||
final target = '${step['target'] ?? ''}'.trim();
|
||||
return [
|
||||
status,
|
||||
if (outcome.isNotEmpty) outcome,
|
||||
if (target.isNotEmpty) '→ $target',
|
||||
].join(' · ');
|
||||
}
|
||||
|
||||
String _text(dynamic value, String fallback) {
|
||||
final text = '${value ?? ''}'.trim();
|
||||
return text.isEmpty ? fallback : text;
|
||||
}
|
||||
|
||||
int? _int(dynamic value) => value is num ? value.toInt() : null;
|
||||
@@ -0,0 +1,203 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../domain/run_models.dart';
|
||||
import 'run_detail_content.dart';
|
||||
|
||||
/// The runs detail with standard Cupertino controls. It has no Material
|
||||
/// ancestor: sections use native Cupertino expansion tiles and grouped list
|
||||
/// sections, and copy feedback is an inline live-region status.
|
||||
Widget buildCupertinoRunDetail({
|
||||
required BuildContext context,
|
||||
required JsonMap run,
|
||||
required bool detailLoading,
|
||||
required String? error,
|
||||
required bool copying,
|
||||
required String? copyStatus,
|
||||
required VoidCallback onBack,
|
||||
required VoidCallback onCopy,
|
||||
}) {
|
||||
final theme = CupertinoTheme.of(context);
|
||||
final prompt = detailPrompt(run);
|
||||
final visits = detailTimeline(run['steps']);
|
||||
final metrics = detailUsageMetrics(run['usage']);
|
||||
return ListView(
|
||||
key: ValueKey<String>('run-detail-${run['id']}'),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
||||
child: Row(
|
||||
children: [
|
||||
CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: onBack,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(CupertinoIcons.back),
|
||||
const SizedBox(width: 4),
|
||||
const Text('Runs'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (copying) const CupertinoActivityIndicator(),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
detailTitle(run),
|
||||
style: theme.textTheme.navLargeTitleTextStyle,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(runStatusLabel(run)),
|
||||
Text('Run ${run['id']} · Pipeline ${detailPipeline(run)}'),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (detailLoading) const _CupertinoNotice('Refreshing run details…'),
|
||||
if (error != null) _CupertinoNotice(error),
|
||||
if (prompt != null)
|
||||
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)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
_fieldSection('Input', run['input'], 'No input recorded.'),
|
||||
_fieldSection('Output', run['output'], 'No output recorded.'),
|
||||
CupertinoListSection.insetGrouped(
|
||||
header: const Text('Timeline'),
|
||||
children: [
|
||||
if (visits.isEmpty)
|
||||
const CupertinoListTile(title: Text('No visits recorded.'))
|
||||
else
|
||||
for (final visit in visits)
|
||||
CupertinoListTile(
|
||||
leading: const Icon(CupertinoIcons.circle),
|
||||
title: Text(visit.title),
|
||||
subtitle: Text(visit.subtitle),
|
||||
),
|
||||
],
|
||||
),
|
||||
CupertinoListSection.insetGrouped(
|
||||
children: [
|
||||
CupertinoExpansionTile(
|
||||
title: const Text('Metrics'),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (metrics.isEmpty)
|
||||
const Text('No reported usage.')
|
||||
else
|
||||
for (final metric in metrics)
|
||||
CupertinoListTile(
|
||||
title: Text(metric.label),
|
||||
subtitle: Text(metric.value),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _fieldSection(String title, dynamic value, String empty) {
|
||||
final text = detailEmpty(value) ? empty : detailJson(value);
|
||||
return CupertinoListSection.insetGrouped(
|
||||
children: [
|
||||
CupertinoExpansionTile(
|
||||
title: Text(title),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
|
||||
child: _CupertinoSelectableText(text),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
class _CupertinoNotice extends StatelessWidget {
|
||||
const _CupertinoNotice(this.text);
|
||||
final String text;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
||||
child: Semantics(liveRegion: true, child: Text(text)),
|
||||
);
|
||||
}
|
||||
|
||||
/// 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,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../domain/run_models.dart';
|
||||
import 'run_detail_content.dart';
|
||||
|
||||
/// The runs detail with standard Material controls.
|
||||
Widget buildMaterialRunDetail({
|
||||
required BuildContext context,
|
||||
required JsonMap run,
|
||||
required bool detailLoading,
|
||||
required String? error,
|
||||
required bool copying,
|
||||
required String? copyStatus,
|
||||
required VoidCallback onBack,
|
||||
required VoidCallback onCopy,
|
||||
}) {
|
||||
final theme = Theme.of(context);
|
||||
final prompt = detailPrompt(run);
|
||||
final visits = detailTimeline(run['steps']);
|
||||
final metrics = detailUsageMetrics(run['usage']);
|
||||
return ListView(
|
||||
key: ValueKey<String>('run-detail-${run['id']}'),
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: TextButton.icon(
|
||||
onPressed: onBack,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
label: const Text('Runs'),
|
||||
),
|
||||
),
|
||||
Text(detailTitle(run), style: theme.textTheme.headlineSmall),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
Chip(label: Text(runStatusLabel(run))),
|
||||
Text('Run ${run['id']}'),
|
||||
Text('Pipeline ${detailPipeline(run)}'),
|
||||
],
|
||||
),
|
||||
if (detailLoading) const _Notice('Refreshing run details…'),
|
||||
if (error != null) _Notice(error),
|
||||
if (prompt != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
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)),
|
||||
),
|
||||
],
|
||||
_fieldSection('Input', run['input'], 'No input recorded.'),
|
||||
_fieldSection('Output', run['output'], 'No output recorded.'),
|
||||
Text('Timeline', style: theme.textTheme.titleLarge),
|
||||
if (visits.isEmpty)
|
||||
const Text('No visits recorded.')
|
||||
else
|
||||
...visits.map(
|
||||
(visit) => ListTile(
|
||||
leading: const Icon(Icons.circle_outlined),
|
||||
title: Text(visit.title),
|
||||
subtitle: Text(visit.subtitle),
|
||||
),
|
||||
),
|
||||
ExpansionTile(
|
||||
title: const Text('Metrics'),
|
||||
children: [
|
||||
if (metrics.isEmpty)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Text('No reported usage.'),
|
||||
)
|
||||
else
|
||||
...metrics.map(
|
||||
(metric) => ListTile(
|
||||
title: Text(metric.label),
|
||||
subtitle: Text(metric.value),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _fieldSection(String title, dynamic value, String empty) {
|
||||
final text = detailEmpty(value) ? empty : detailJson(value);
|
||||
return ExpansionTile(
|
||||
title: Text(title),
|
||||
children: [
|
||||
Padding(padding: const EdgeInsets.all(16), child: SelectableText(text)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
class _Notice extends StatelessWidget {
|
||||
const _Notice(this.text);
|
||||
final String text;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Semantics(liveRegion: true, child: Text(text)),
|
||||
);
|
||||
}
|
||||
@@ -1,124 +1,133 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'run_detail_content.dart';
|
||||
import 'run_detail_cupertino.dart';
|
||||
import 'run_detail_material.dart';
|
||||
import 'runs_controller.dart';
|
||||
|
||||
class RunDetailView extends StatelessWidget {
|
||||
const RunDetailView({super.key, required this.controller, required this.onBack});
|
||||
class RunDetailView extends StatefulWidget {
|
||||
const RunDetailView({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.onBack,
|
||||
});
|
||||
|
||||
final RunsController controller;
|
||||
final VoidCallback onBack;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final run = controller.detail;
|
||||
if (controller.detailLoading && run == null) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
if (run == null) {
|
||||
State<RunDetailView> createState() => _RunDetailViewState();
|
||||
}
|
||||
|
||||
class _RunDetailViewState extends State<RunDetailView> {
|
||||
bool _copying = false;
|
||||
String? _copyStatus;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AnimatedBuilder(
|
||||
animation: widget.controller,
|
||||
builder: (context, _) {
|
||||
final cupertino = _usesCupertino(context);
|
||||
final run = widget.controller.detail;
|
||||
if (run == null) return _placeholder(context, cupertino: cupertino);
|
||||
final prompt = detailPrompt(run);
|
||||
return cupertino
|
||||
? buildCupertinoRunDetail(
|
||||
context: context,
|
||||
run: run,
|
||||
detailLoading: widget.controller.detailLoading,
|
||||
error: widget.controller.error,
|
||||
copying: _copying,
|
||||
copyStatus: _copyStatus,
|
||||
onBack: widget.onBack,
|
||||
onCopy: () => _copyPrompt(prompt ?? '', cupertino: true),
|
||||
)
|
||||
: buildMaterialRunDetail(
|
||||
context: context,
|
||||
run: run,
|
||||
detailLoading: widget.controller.detailLoading,
|
||||
error: widget.controller.error,
|
||||
copying: _copying,
|
||||
copyStatus: _copyStatus,
|
||||
onBack: widget.onBack,
|
||||
onCopy: () => _copyPrompt(prompt ?? '', cupertino: false),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
/// CupertinoApp supplies CupertinoLocalizations only, while MaterialApp
|
||||
/// supplies MaterialLocalizations. This distinguishes the two hosts without
|
||||
/// assuming a desktop browser's target platform.
|
||||
bool _usesCupertino(BuildContext context) =>
|
||||
Localizations.of<MaterialLocalizations>(context, MaterialLocalizations) ==
|
||||
null;
|
||||
|
||||
Widget _placeholder(BuildContext context, {required bool cupertino}) {
|
||||
if (widget.controller.detailLoading) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(controller.error ?? 'Run details unavailable.'),
|
||||
FilledButton(
|
||||
onPressed: onBack,
|
||||
child: const Text('Back to runs'),
|
||||
),
|
||||
if (cupertino)
|
||||
const CupertinoActivityIndicator()
|
||||
else
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(height: 12),
|
||||
const Text('Loading run details…'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
final input = run['input'] is Map ? run['input'] as Map : const {};
|
||||
final output = run['output'] is Map ? run['output'] as Map : const {};
|
||||
final steps = run['steps'] is List ? run['steps'] as List : const [];
|
||||
final prompt = input['prompt'];
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
TextButton.icon(
|
||||
onPressed: onBack,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
label: const Text('Runs'),
|
||||
),
|
||||
Text(
|
||||
'${run['title'] ?? run['name'] ?? 'Run ${run['id']}'}',
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
children: [
|
||||
Chip(label: Text('${run['status'] ?? 'unknown'}')),
|
||||
Text('Run ${run['id']}'),
|
||||
Text('Pipeline ${run['name'] ?? 'unavailable'}'),
|
||||
],
|
||||
),
|
||||
if (prompt is String) ...[
|
||||
final message = widget.controller.error ?? 'Run details unavailable.';
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Text(message, textAlign: TextAlign.center),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'Original prompt',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
tooltip: 'Copy prompt',
|
||||
onPressed: () => _copy(context, prompt),
|
||||
icon: const Icon(Icons.copy),
|
||||
),
|
||||
],
|
||||
),
|
||||
SelectableText(prompt),
|
||||
],
|
||||
_section(context, 'Input', input),
|
||||
_section(context, 'Output', output),
|
||||
Text('Timeline', style: Theme.of(context).textTheme.titleLarge),
|
||||
if (steps.isEmpty)
|
||||
const Text('No visits recorded.')
|
||||
else
|
||||
...steps.whereType<Map>().map(
|
||||
(step) => ListTile(
|
||||
leading: const Icon(Icons.circle_outlined),
|
||||
title: Text(
|
||||
'${step['stage'] ?? 'Stage unavailable'} · visit ${step['sequence'] ?? '?'}',
|
||||
),
|
||||
subtitle: Text(
|
||||
'${step['status'] ?? 'Status unavailable'}${step['outcome'] == null ? '' : ' · ${step['outcome']}'}',
|
||||
),
|
||||
if (cupertino)
|
||||
CupertinoButton(
|
||||
onPressed: widget.onBack,
|
||||
child: const Text('Back to runs'),
|
||||
)
|
||||
else
|
||||
FilledButton(
|
||||
onPressed: widget.onBack,
|
||||
child: const Text('Back to runs'),
|
||||
),
|
||||
),
|
||||
_section(context, 'Metrics', run['usage'] is Map ? run['usage'] as Map : const {}),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _section(BuildContext context, String title, Map value) =>
|
||||
ExpansionTile(
|
||||
title: Text(title),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: SelectableText(
|
||||
value.isEmpty
|
||||
? 'No ${title.toLowerCase()} recorded.'
|
||||
: value.entries.map((e) => '${e.key}: ${e.value}').join('\n'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
Future<void> _copy(BuildContext context, String text) async {
|
||||
// Clipboard failure is reported rather than silently substituting title/output.
|
||||
/// Copies the stored prompt byte-for-byte. A refusal is surfaced, never
|
||||
/// replaced by copying a title or the formatted detail.
|
||||
Future<void> _copyPrompt(String prompt, {required bool cupertino}) async {
|
||||
if (_copying) return;
|
||||
setState(() => _copying = true);
|
||||
String message;
|
||||
try {
|
||||
await Clipboard.setData(ClipboardData(text: text));
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('Prompt copied.')));
|
||||
}
|
||||
await Clipboard.setData(ClipboardData(text: prompt));
|
||||
message = 'Prompt copied to clipboard.';
|
||||
} catch (_) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('Could not copy prompt.')));
|
||||
}
|
||||
message = 'Could not copy prompt to clipboard.';
|
||||
}
|
||||
if (!mounted) return;
|
||||
final scaffold = cupertino ? null : Scaffold.maybeOf(context);
|
||||
final inline = cupertino || scaffold == null;
|
||||
setState(() {
|
||||
_copying = false;
|
||||
_copyStatus = inline ? message : null;
|
||||
});
|
||||
if (!cupertino && scaffold != null) {
|
||||
ScaffoldMessenger.maybeOf(
|
||||
context,
|
||||
)?.showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user