merge(app): land chevron pagers

This commit is contained in:
2026-10-23 17:15:49 +01:00
9 changed files with 204 additions and 225 deletions
@@ -1,3 +1,4 @@
import '../../../ui/navigation/chevron_pager.dart';
import 'dart:typed_data';
import 'package:flutter/cupertino.dart';
@@ -182,6 +183,9 @@ class _Actions extends StatelessWidget {
}
}
const artifactPreviousKey = ValueKey<String>('artifact-previous');
const artifactNextKey = ValueKey<String>('artifact-next');
class _Pager extends StatelessWidget {
const _Pager({
required this.index,
@@ -200,48 +204,17 @@ class _Pager extends StatelessWidget {
if (count <= 1) return const SizedBox.shrink();
final hasPrevious = pagedIndex(index, -1, count) != index;
final hasNext = pagedIndex(index, 1, count) != index;
if (usesCupertinoHost(context)) {
return SafeArea(
top: false,
child: Wrap(
alignment: WrapAlignment.spaceBetween,
children: [
CupertinoButton(
onPressed: hasPrevious ? onPrevious : null,
child: const Text('Previous artifact'),
),
CupertinoButton(
onPressed: hasNext ? onNext : null,
child: const Text('Next artifact'),
),
],
),
);
}
return SafeArea(
top: false,
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(8, 0, 8, 4),
// A `Row` clips the second labelled button once 2x text is wider than
// the viewport; a `Wrap` keeps both controls whole and lets them take
// separate lines, like the Cupertino pager.
child: Wrap(
alignment: WrapAlignment.spaceBetween,
spacing: 8,
runSpacing: 4,
children: [
TextButton.icon(
onPressed: hasPrevious ? onPrevious : null,
icon: const Icon(Icons.arrow_back),
label: const Text('Previous artifact'),
),
TextButton.icon(
onPressed: hasNext ? onNext : null,
icon: const Icon(Icons.arrow_forward),
label: const Text('Next artifact'),
),
],
),
child: ChevronPager(
index: index,
count: count,
previousLabel: 'Previous artifact',
nextLabel: 'Next artifact',
previousKey: artifactPreviousKey,
nextKey: artifactNextKey,
onPrevious: hasPrevious ? onPrevious : null,
onNext: hasNext ? onNext : null,
),
);
}
@@ -161,12 +161,6 @@ class _ChangesViewerState extends State<ChangesViewer> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ChangesVisitPager(
index: _visitIndex,
count: captures.length,
onPrevious: () => _stepVisit(-1),
onNext: () => _stepVisit(1),
),
StageCaptureSection(
stage: visit,
query: _query,
@@ -184,6 +178,14 @@ class _ChangesViewerState extends State<ChangesViewer> {
),
),
),
// Previous/next visit sit at the bottom right, under the visit.
if (visit != null)
ChangesVisitPager(
index: _visitIndex,
count: captures.length,
onPrevious: () => _stepVisit(-1),
onNext: () => _stepVisit(1),
),
],
);
}
@@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../../../ui/navigation/chevron_pager.dart';
import '../domain/change_kind.dart';
import '../domain/change_wording.dart';
import '../domain/file_change.dart';
@@ -276,9 +277,12 @@ class _FileDiffPageState extends State<FileDiffPage> {
);
final pager = count < 2
? null
: FileDiffPager(
: ChevronPager(
key: const ValueKey('file-diff-pager'),
index: _index,
count: count,
previousLabel: 'Previous file',
nextLabel: 'Next file',
onPrevious: _index > 0 ? () => _step(-1) : null,
onNext: _index < count - 1 ? () => _step(1) : null,
);
@@ -303,64 +307,3 @@ class _FileDiffPageState extends State<FileDiffPage> {
);
}
}
/// Previous and next as chevrons in one row at the bottom right, with the
/// position between them read as `2 of 5`.
class FileDiffPager extends StatelessWidget {
const FileDiffPager({
super.key,
required this.index,
required this.count,
this.onPrevious,
this.onNext,
});
final int index;
final int count;
final VoidCallback? onPrevious;
final VoidCallback? onNext;
@override
Widget build(BuildContext context) {
final cupertino = usesCupertino(context);
Widget button(
IconData material,
IconData ios,
String tip,
VoidCallback? on,
) => cupertino
? Semantics(
button: true,
label: tip,
child: CupertinoButton(
padding: const EdgeInsets.all(8),
onPressed: on,
child: Icon(ios),
),
)
: IconButton(onPressed: on, tooltip: tip, icon: Icon(material));
return Padding(
key: const ValueKey('file-diff-pager'),
padding: const EdgeInsets.fromLTRB(16, 4, 8, 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text('${index + 1} of $count'),
const SizedBox(width: 4),
button(
Icons.chevron_left,
CupertinoIcons.chevron_left,
'Previous file',
onPrevious,
),
button(
Icons.chevron_right,
CupertinoIcons.chevron_right,
'Next file',
onNext,
),
],
),
);
}
}
@@ -1,8 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../domain/change_wording.dart';
import 'change_style.dart';
import '../../../ui/navigation/chevron_pager.dart';
/// The Changes page's Previous/Next pager over the run's recorded stage visits.
///
@@ -31,81 +30,16 @@ class ChangesVisitPager extends StatelessWidget {
@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),
return ChevronPager(
index: index,
count: count,
previousLabel: 'Previous visit',
nextLabel: 'Next visit',
previousKey: previousKey,
nextKey: nextKey,
positionKey: const ValueKey<String>('changes-visit-position'),
onPrevious: index > 0 ? onPrevious : null,
onNext: index < count - 1 ? onNext : null,
);
}
}
+98
View File
@@ -0,0 +1,98 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/host.dart';
/// Previous and next as chevrons in one row at the bottom right, with the
/// position before them (`2 of 5`). Each chevron is named for assistive
/// technology ([previousLabel], [nextLabel]); an end of the list disables its
/// chevron rather than hiding it, so the row never shifts.
class ChevronPager extends StatelessWidget {
const ChevronPager({
super.key,
required this.index,
required this.count,
required this.previousLabel,
required this.nextLabel,
this.onPrevious,
this.onNext,
this.previousKey,
this.nextKey,
this.positionKey,
});
final int index;
final int count;
final String previousLabel;
final String nextLabel;
final VoidCallback? onPrevious;
final VoidCallback? onNext;
final Key? previousKey;
final Key? nextKey;
final Key? positionKey;
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
Widget chevron({
required Key? key,
required bool previous,
required String label,
required VoidCallback? onPressed,
}) {
if (cupertino) {
return Semantics(
button: true,
enabled: onPressed != null,
label: label,
excludeSemantics: true,
child: CupertinoButton(
key: key,
padding: const EdgeInsets.all(8),
onPressed: onPressed,
child: Icon(
previous
? CupertinoIcons.chevron_left
: CupertinoIcons.chevron_right,
),
),
);
}
return IconButton(
key: key,
tooltip: label,
onPressed: onPressed,
icon: Icon(previous ? Icons.chevron_left : Icons.chevron_right),
);
}
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 8, 4),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Flexible(
child: Text(
'${index + 1} of $count',
key: positionKey,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 4),
chevron(
key: previousKey,
previous: true,
label: previousLabel,
onPressed: onPrevious,
),
chevron(
key: nextKey,
previous: false,
label: nextLabel,
onPressed: onNext,
),
],
),
);
}
}
@@ -5,6 +5,7 @@ import 'dart:typed_data';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_body.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_video_player.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart';
@@ -59,14 +60,6 @@ Future<void> _pumpViewer(
await tester.pumpAndSettle();
}
TextButton _textButton(WidgetTester tester, String label) {
return tester.widget<TextButton>(
find
.ancestor(of: find.text(label), matching: find.byType(TextButton))
.first,
);
}
const String _markdownBody =
'# Report\n'
'\n'
@@ -359,24 +352,36 @@ void main() {
);
expect(find.text('1 of 3 · image/png'), findsOneWidget);
expect(_textButton(tester, 'Previous artifact').onPressed, isNull);
expect(_textButton(tester, 'Next artifact').onPressed, isNotNull);
expect(
tester.widget<IconButton>(find.byKey(artifactPreviousKey)).onPressed,
isNull,
);
expect(
tester.widget<IconButton>(find.byKey(artifactNextKey)).onPressed,
isNotNull,
);
await tester.tap(find.text('Next artifact'));
await tester.tap(find.byKey(artifactNextKey));
await tester.pumpAndSettle();
expect(find.text('2 of 3 · image/png'), findsOneWidget);
expect(find.text('review · visit 2'), findsOneWidget);
expect(_textButton(tester, 'Previous artifact').onPressed, isNotNull);
expect(
tester.widget<IconButton>(find.byKey(artifactPreviousKey)).onPressed,
isNotNull,
);
await tester.tap(find.text('Next artifact'));
await tester.tap(find.byKey(artifactNextKey));
await tester.pumpAndSettle();
expect(find.text('3 of 3 · image/png'), findsOneWidget);
expect(_textButton(tester, 'Next artifact').onPressed, isNull);
await tester.tap(find.text('Next artifact'));
expect(
tester.widget<IconButton>(find.byKey(artifactNextKey)).onPressed,
isNull,
);
await tester.tap(find.byKey(artifactNextKey));
await tester.pumpAndSettle();
expect(find.text('3 of 3 · image/png'), findsOneWidget);
await tester.tap(find.text('Previous artifact'));
await tester.tap(find.byKey(artifactPreviousKey));
await tester.pumpAndSettle();
expect(find.text('2 of 3 · image/png'), findsOneWidget);
});
@@ -544,9 +549,12 @@ void main() {
);
expect(tester.takeException(), isNull);
// Both labelled controls are whole: a clipped Row overflowed the viewport.
for (final label in ['Previous artifact', 'Next artifact']) {
final rect = tester.getRect(find.text(label));
// Both chevrons are whole and on screen at the bottom right.
for (final (label, key) in [
('Previous artifact', artifactPreviousKey),
('Next artifact', artifactNextKey),
]) {
final rect = tester.getRect(find.byKey(key));
expect(rect.left, greaterThanOrEqualTo(0), reason: label);
expect(rect.right, lessThanOrEqualTo(320), reason: label);
expect(rect.width, greaterThan(0), reason: label);
@@ -42,7 +42,7 @@ void main() {
// The aggregate counts each path once across both visits, and does not
// change as the operator pages.
expect(find.text('3 files changed'), findsOneWidget);
expect(find.text('1 of 2 recorded visits'), findsOneWidget);
expect(find.text('1 of 2'), findsOneWidget);
expect(find.text('implementer'), findsOneWidget);
expect(find.text('Visit 1 · completed'), findsOneWidget);
expect(find.text('lib/a.dart'), findsOneWidget);
@@ -57,7 +57,7 @@ void main() {
expect(find.text('lib/c.dart'), findsOneWidget);
expect(find.text('lib/a.dart'), findsNothing);
expect(find.text('3 files changed'), findsOneWidget);
expect(find.text('2 of 2 recorded visits'), findsOneWidget);
expect(find.text('2 of 2'), findsOneWidget);
await tester.tap(find.byKey(ChangesVisitPager.previousKey));
await tester.pump();
@@ -65,17 +65,33 @@ void main() {
expect(find.text('implementer'), findsOneWidget);
expect(find.text('lib/a.dart'), findsOneWidget);
expect(find.text('lib/c.dart'), findsNothing);
expect(find.text('1 of 2 recorded visits'), findsOneWidget);
expect(find.text('1 of 2'), findsOneWidget);
},
);
testWidgets('visit chevrons share one row at the bottom right', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(materialHost(ChangesViewer(steps: twoVisitRun())));
final previous = tester.getRect(find.byKey(ChangesVisitPager.previousKey));
final next = tester.getRect(find.byKey(ChangesVisitPager.nextKey));
expect(previous.center.dy, moreOrLessEquals(next.center.dy));
expect(previous.right, lessThanOrEqualTo(next.left));
expect(next.right, greaterThan(390 - 32));
expect(next.bottom, greaterThan(844 - 80));
});
testWidgets('paging stops at both ends instead of wrapping', (tester) async {
await tester.pumpWidget(materialHost(ChangesViewer(steps: twoVisitRun())));
TextButton previous() =>
tester.widget<TextButton>(find.byKey(ChangesVisitPager.previousKey));
TextButton next() =>
tester.widget<TextButton>(find.byKey(ChangesVisitPager.nextKey));
IconButton previous() =>
tester.widget<IconButton>(find.byKey(ChangesVisitPager.previousKey));
IconButton next() =>
tester.widget<IconButton>(find.byKey(ChangesVisitPager.nextKey));
expect(previous().onPressed, isNull);
expect(next().onPressed, isNotNull);
@@ -110,9 +126,12 @@ void main() {
),
),
);
expect(find.text('Previous visit'), findsNothing);
expect(find.text('Next visit'), findsNothing);
expect(find.textContaining('recorded visits'), findsNothing);
expect(find.byKey(ChangesVisitPager.previousKey), findsNothing);
expect(find.byKey(ChangesVisitPager.nextKey), findsNothing);
expect(
find.byKey(const ValueKey<String>('changes-visit-position')),
findsNothing,
);
// The single visit still keeps its identity heading.
expect(find.text('implementer'), findsOneWidget);
expect(find.text('Visit 1 · completed'), findsOneWidget);
@@ -162,7 +181,7 @@ void main() {
expect(tester.takeException(), isNull);
expect(find.text('implementer'), findsOneWidget);
expect(find.text('Visit 1 · completed'), findsOneWidget);
expect(find.text('Previous visit'), findsNothing);
expect(find.byKey(ChangesVisitPager.previousKey), findsNothing);
});
testWidgets('the pager stays reachable at 320x720 with 2x text', (
@@ -178,14 +197,14 @@ void main() {
),
);
expect(tester.takeException(), isNull);
expect(find.text('Previous visit'), findsOneWidget);
expect(find.text('Next visit'), findsOneWidget);
expect(find.byKey(ChangesVisitPager.previousKey), findsOneWidget);
expect(find.byKey(ChangesVisitPager.nextKey), findsOneWidget);
// At 2x text the fixed summary and filter leave a short scroll viewport;
// the pager is still reachable by scrolling the visit body.
await tester.ensureVisible(find.text('Next visit'));
await tester.ensureVisible(find.byKey(ChangesVisitPager.nextKey));
await tester.pump();
await tester.tap(find.text('Next visit'));
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
await tester.pump();
expect(tester.takeException(), isNull);
expect(find.text('reviewer'), findsOneWidget);
@@ -206,8 +225,8 @@ void main() {
);
expect(previous.onPressed, isNull);
expect(next.onPressed, isNotNull);
expect(find.text('Previous visit'), findsOneWidget);
expect(find.text('Next visit'), findsOneWidget);
expect(find.byKey(ChangesVisitPager.previousKey), findsOneWidget);
expect(find.byKey(ChangesVisitPager.nextKey), findsOneWidget);
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
await tester.pump();
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/changes/changes.dart';
import 'package:pipelines_app/features/changes/widgets/visit_pager.dart';
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
@@ -121,13 +122,13 @@ void main() {
// heading identifies the evidence, and Next reaches the second visit.
expect(find.text('Visit 1 · completed'), findsOneWidget);
expect(find.text('implementer'), findsOneWidget);
expect(find.text('Next visit'), findsOneWidget);
await tester.tap(find.text('Next visit'));
expect(find.byKey(ChangesVisitPager.nextKey), findsOneWidget);
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
await tester.pump();
expect(find.text('reviewer'), findsOneWidget);
expect(find.text('Visit 1 · completed'), findsOneWidget);
expect(find.text('lib/feature.dart'), findsNothing);
await tester.tap(find.text('Previous visit'));
await tester.tap(find.byKey(ChangesVisitPager.previousKey));
await tester.pump();
expect(find.text('lib/feature.dart'), findsOneWidget);
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/changes/changes.dart';
import 'package:pipelines_app/features/changes/widgets/visit_pager.dart';
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
import 'package:pipelines_app/features/runs/ui/run_changes_action.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
@@ -148,7 +149,7 @@ void main() {
expect(find.text('lib/feature.dart'), findsOneWidget);
expect(find.text('implementer'), findsOneWidget);
expect(find.text('Visit 1 · completed'), findsOneWidget);
await tester.tap(find.text('Next visit'));
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
await tester.pump();
expect(find.text('reviewer'), findsOneWidget);
expect(find.text(missingCaptureDetail), findsOneWidget);