174 lines
5.1 KiB
Dart
174 lines
5.1 KiB
Dart
import '../../../ui/theme/app_theme.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/status/run_status_icon.dart';
|
|
import '../domain/run_models.dart';
|
|
import 'run_detail_content.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: const EdgeInsets.all(16),
|
|
children: const [Text('No visits recorded.')],
|
|
);
|
|
}
|
|
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,
|
|
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: 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,
|
|
});
|
|
|
|
final DetailVisit visit;
|
|
final bool selected;
|
|
final bool cupertino;
|
|
final VoidCallback? onTap;
|
|
|
|
/// 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);
|
|
final color = 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,
|
|
);
|
|
}
|
|
}
|