Files
pipelines/app/lib/features/changes/widgets/visit_pager.dart
T
alan 9532ecddcf feat(app): page the run Changes surface one recorded visit at a time
The run-wide header, note, filter and matched-path counter still describe
every visit; below them Previous/Next move through the recorded visits in
run order without wrapping, and the shown visit keeps its own stage and
Visit N heading. A single recorded visit renders no pager.
2026-10-22 15:56:30 +01:00

112 lines
3.3 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../domain/change_wording.dart';
import 'change_style.dart';
/// The Changes page's Previous/Next pager over the run's recorded stage visits.
///
/// It only moves between the captures the viewer already holds and never wraps:
/// the first recorded visit has no previous page and the last none after it.
/// The shown visit's own heading (its stage and visit number) stays with the
/// capture section below, so paging never loses which visit is on screen.
class ChangesVisitPager extends StatelessWidget {
const ChangesVisitPager({
super.key,
required this.index,
required this.count,
required this.onPrevious,
required this.onNext,
});
static const previousKey = ValueKey<String>('changes-previous-visit');
static const nextKey = ValueKey<String>('changes-next-visit');
/// The shown visit's zero-based position in the run's recorded visits.
final int index;
final int count;
final VoidCallback onPrevious;
final VoidCallback onNext;
@override
Widget build(BuildContext context) {
if (count <= 1) return const SizedBox.shrink();
final hasPrevious = index > 0;
final hasNext = index < count - 1;
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
'${changePositionLabel(index, count)} recorded visits',
key: const ValueKey<String>('changes-visit-position'),
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodySmall,
),
const SizedBox(height: 4),
// A `Wrap` keeps both controls whole and lets them take separate
// lines at large text sizes or on a narrow page.
Wrap(
alignment: WrapAlignment.spaceBetween,
spacing: 8,
runSpacing: 4,
children: [
_button(
context,
key: previousKey,
label: 'Previous visit',
enabled: hasPrevious,
onPressed: onPrevious,
previous: true,
),
_button(
context,
key: nextKey,
label: 'Next visit',
enabled: hasNext,
onPressed: onNext,
previous: false,
),
],
),
],
),
);
}
Widget _button(
BuildContext context, {
required Key key,
required String label,
required bool enabled,
required VoidCallback onPressed,
required bool previous,
}) {
if (usesCupertino(context)) {
return CupertinoButton(
key: key,
padding: EdgeInsets.zero,
onPressed: enabled ? onPressed : null,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
previous ? CupertinoIcons.back : CupertinoIcons.forward,
size: 20,
),
const SizedBox(width: 4),
Text(label),
],
),
);
}
return TextButton.icon(
key: key,
onPressed: enabled ? onPressed : null,
icon: Icon(previous ? Icons.arrow_back : Icons.arrow_forward),
label: Text(label),
);
}
}