1bf2ae41c4
A completed step's outcome chip took the success colour, so 'rejected' read green beside 'success'. Outcome chips now get one colour per distinct outcome name in the run (assigned by first appearance, from a well-separated hue list that continues by the golden angle), so equal names match and different names never share a colour. No outcome word is wired to a colour; the status glyph still shows the step's state.
195 lines
6.0 KiB
Dart
195 lines
6.0 KiB
Dart
import '../../../ui/theme/app_theme.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/status/outcome_palette.dart';
|
|
import '../../../ui/status/run_status_icon.dart';
|
|
import '../domain/run_models.dart';
|
|
import 'run_detail_content.dart';
|
|
import '../../../ui/adaptive/floating_bar_layout.dart';
|
|
|
|
/// The Timeline tab's recorded visits, one native row per visit.
|
|
///
|
|
/// [onSelected] receives the row's index in [visits], so the caller opens
|
|
/// exactly the recorded step it was built from. [selectedSequence] highlights a
|
|
/// row when a selection is applied while the list is rendered; the current
|
|
/// flow replaces the rows with the pane, so it only matters for a defensive
|
|
/// host that keeps both visible. Only an actual recorded visit can match, so an
|
|
/// unvisited stage leaves every row unselected.
|
|
class RunTimelineList extends StatelessWidget {
|
|
const RunTimelineList({
|
|
super.key,
|
|
required this.visits,
|
|
required this.cupertino,
|
|
this.selectedSequence,
|
|
this.onSelected,
|
|
});
|
|
|
|
final List<DetailVisit> visits;
|
|
final bool cupertino;
|
|
final int? selectedSequence;
|
|
final ValueChanged<int>? onSelected;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (visits.isEmpty) {
|
|
return ListView(
|
|
key: const Key('run-detail-tab-body-timeline'),
|
|
padding: withBarClearance(context, const EdgeInsets.all(16)),
|
|
children: const [Text('No visits recorded.')],
|
|
);
|
|
}
|
|
// One colour per distinct outcome name across the whole run, so the same
|
|
// outcome reads the same on every row and different ones never match.
|
|
final palette = OutcomePalette(visits.map((visit) => visit.outcome));
|
|
final rows = [
|
|
for (var index = 0; index < visits.length; index += 1)
|
|
RunTimelineRow(
|
|
key: ValueKey(
|
|
'run-timeline-visit-${visits[index].sequence ?? index}',
|
|
),
|
|
visit: visits[index],
|
|
selected: visits[index].sequence == selectedSequence,
|
|
cupertino: cupertino,
|
|
palette: palette,
|
|
onTap: onSelected == null ? null : () => onSelected!(index),
|
|
),
|
|
];
|
|
if (cupertino) {
|
|
return ListView(
|
|
key: const Key('run-detail-tab-body-timeline'),
|
|
children: [
|
|
CupertinoListSection.insetGrouped(
|
|
backgroundColor: AppColors.groupedBackground,
|
|
header: const Text('Timeline'),
|
|
children: rows,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
return ListView(
|
|
key: const Key('run-detail-tab-body-timeline'),
|
|
padding: withBarClearance(
|
|
context,
|
|
const EdgeInsets.symmetric(vertical: 8),
|
|
),
|
|
children: rows,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// One recorded visit. [selected] marks the row an applied selection identifies;
|
|
/// the current flow opens the pane instead of leaving a highlighted row. It is
|
|
/// never true for a stage with no recorded visit.
|
|
class RunTimelineRow extends StatelessWidget {
|
|
const RunTimelineRow({
|
|
super.key,
|
|
required this.visit,
|
|
required this.selected,
|
|
required this.cupertino,
|
|
this.onTap,
|
|
this.palette,
|
|
});
|
|
|
|
final DetailVisit visit;
|
|
final bool selected;
|
|
final bool cupertino;
|
|
final VoidCallback? onTap;
|
|
|
|
/// The run's outcome colours; without one the row colours its own outcome
|
|
/// as the first (and only) name.
|
|
final OutcomePalette? palette;
|
|
|
|
/// The visit's state for its glyph: the outcome when it has one (a completed
|
|
/// step can still have failed), else the step status.
|
|
String get _state {
|
|
final outcome = visit.outcome.toLowerCase();
|
|
if (outcome == 'error' || outcome == 'failed' || outcome == 'failure') {
|
|
return 'failed';
|
|
}
|
|
return runStateOf(visit.status);
|
|
}
|
|
|
|
/// One line under the title: where the visit went and how long it took.
|
|
String get _detail => [
|
|
if (visit.target.isNotEmpty) '→ ${visit.target}',
|
|
?visit.duration,
|
|
].join(' · ');
|
|
|
|
Widget _outcome(BuildContext context) {
|
|
final label = visit.outcome.isNotEmpty
|
|
? visit.outcome
|
|
: (visit.status.isEmpty ? 'unknown' : visit.status);
|
|
// An outcome is coloured by its name (no word is wired to a colour); a
|
|
// visit with no outcome yet keeps its status colour.
|
|
final color = visit.outcome.isNotEmpty
|
|
? (palette ?? OutcomePalette([visit.outcome])).colorFor(
|
|
context,
|
|
visit.outcome,
|
|
)
|
|
: runStatusColor(_state).resolveFrom(context);
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
|
decoration: BoxDecoration(
|
|
color: color.withValues(alpha: 0.14),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: Text(
|
|
label,
|
|
style: TextStyle(
|
|
color: color,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final leading = RunStatusIcon(
|
|
state: _state,
|
|
label: visit.status.isEmpty ? 'Status unavailable' : visit.status,
|
|
size: 22,
|
|
);
|
|
final title = Text(
|
|
visit.title,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
);
|
|
final detail = _detail;
|
|
// The outcome chip leads the second line, so the title keeps the width.
|
|
final subtitle = Wrap(
|
|
spacing: 8,
|
|
runSpacing: 4,
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
children: [_outcome(context), if (detail.isNotEmpty) Text(detail)],
|
|
);
|
|
if (cupertino) {
|
|
return Semantics(
|
|
selected: selected,
|
|
child: CupertinoListTile(
|
|
leading: leading,
|
|
title: title,
|
|
subtitle: subtitle,
|
|
trailing: const CupertinoListTileChevron(),
|
|
backgroundColor: selected
|
|
? CupertinoDynamicColor.resolve(
|
|
CupertinoColors.secondarySystemFill,
|
|
context,
|
|
)
|
|
: null,
|
|
onTap: onTap,
|
|
),
|
|
);
|
|
}
|
|
return ListTile(
|
|
selected: selected,
|
|
leading: leading,
|
|
title: title,
|
|
subtitle: subtitle,
|
|
onTap: onTap,
|
|
);
|
|
}
|
|
}
|