fix(app): close the artifact viewer with Escape
This commit is contained in:
@@ -245,6 +245,8 @@ class _ArtifactViewerPageState extends State<ArtifactViewerPage> {
|
||||
body = ArrowKeyPager(
|
||||
onPrevious: () => _step(-1),
|
||||
onNext: () => _step(1),
|
||||
// Escape closes the viewer, like the web's overlay.
|
||||
onEscape: () => Navigator.of(context).maybePop(),
|
||||
child: body,
|
||||
);
|
||||
if (usesCupertinoHost(context)) {
|
||||
|
||||
@@ -9,6 +9,7 @@ class ArrowKeyPager extends StatelessWidget {
|
||||
super.key,
|
||||
required this.onPrevious,
|
||||
required this.onNext,
|
||||
this.onEscape,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
@@ -17,6 +18,10 @@ class ArrowKeyPager extends StatelessWidget {
|
||||
|
||||
/// Null at the last item.
|
||||
final VoidCallback? onNext;
|
||||
|
||||
/// Escape, when the surface can be dismissed (a viewer page). Absent means
|
||||
/// Escape keeps whatever meaning the surrounding page gives it.
|
||||
final VoidCallback? onEscape;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
@@ -26,6 +31,9 @@ class ArrowKeyPager extends StatelessWidget {
|
||||
onPrevious?.call(),
|
||||
const SingleActivator(LogicalKeyboardKey.arrowRight): () =>
|
||||
onNext?.call(),
|
||||
if (onEscape != null)
|
||||
const SingleActivator(LogicalKeyboardKey.escape): () =>
|
||||
onEscape!.call(),
|
||||
},
|
||||
child: Focus(autofocus: true, child: child),
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.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';
|
||||
@@ -616,4 +617,37 @@ void main() {
|
||||
expect(rect.width, greaterThan(0), reason: label);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('Escape closes the viewer back to the gallery', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ArtifactGalleryPage(
|
||||
steps: <JsonMap>[
|
||||
step(
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
artifact(
|
||||
'shot.png',
|
||||
url: '/artifacts/1/1/shot.png',
|
||||
contentType: 'image/png',
|
||||
sizeBytes: 1024,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
configuredEndpoint: _endpoint,
|
||||
fetch: (_) async => ArtifactFetchResult(status: 200, bytes: _png),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('shot.png'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
||||
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(ArtifactViewerPage), findsNothing);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user