118 lines
3.5 KiB
Dart
118 lines
3.5 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.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(
|
|
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;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (cupertino) {
|
|
return Semantics(
|
|
selected: selected,
|
|
child: CupertinoListTile(
|
|
leading: Icon(
|
|
selected
|
|
? CupertinoIcons.check_mark_circled_solid
|
|
: CupertinoIcons.circle,
|
|
),
|
|
title: Text(visit.title),
|
|
subtitle: Text(visit.subtitle),
|
|
trailing: selected ? const Icon(CupertinoIcons.check_mark) : null,
|
|
backgroundColor: selected
|
|
? CupertinoDynamicColor.resolve(
|
|
CupertinoColors.secondarySystemFill,
|
|
context,
|
|
)
|
|
: null,
|
|
onTap: onTap,
|
|
),
|
|
);
|
|
}
|
|
return ListTile(
|
|
selected: selected,
|
|
leading: Icon(selected ? Icons.check_circle : Icons.circle_outlined),
|
|
title: Text(visit.title),
|
|
subtitle: Text(visit.subtitle),
|
|
onTap: onTap,
|
|
);
|
|
}
|
|
}
|