Require double back to exit Android tab roots

This commit is contained in:
2026-10-24 02:23:15 +01:00
parent 54f74ade33
commit 4e6771aa24
6 changed files with 233 additions and 11 deletions
+94 -5
View File
@@ -1,4 +1,5 @@
import 'package:flutter/widgets.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/app_route.dart';
import 'package:pipelines_app/application/app_router.dart';
@@ -41,19 +42,107 @@ void main() {
expect(runs, 1);
// A pipeline stage returns to its pipeline, then to the list, and the
// list leaves Back to the platform.
// list arms exit, then leaves Back to the platform.
router.goTo(AppRoute.pipelineStage(4, 'plan', version: 2));
expect(await router.popRoute(), isTrue);
expect(router.route, AppRoute.pipeline(4, version: 2));
expect(await router.popRoute(), isTrue);
expect(router.route, AppRoute.pipelines);
expect(await router.popRoute(), isTrue);
expect(await router.popRoute(), isFalse);
});
test('system Back on a list destination stays with the platform', () async {
final router = delegate(AppRoute.chat);
addTearDown(router.dispose);
test(
'Android list Back arms exit before handing it to the platform',
() async {
final router = delegate(AppRoute.chat);
addTearDown(router.dispose);
expect(await router.popRoute(), isTrue);
expect(await router.popRoute(), isFalse);
},
);
for (final root in [
AppRoute.pipelines,
AppRoute.runs,
AppRoute.runsForPipeline(3),
AppRoute.chat,
AppRoute.settings,
]) {
testWidgets('${root.path} root exit expires and navigation clears it', (
tester,
) async {
final router = AppRouterDelegate(
builder: (_, route) => Scaffold(body: Text(route.path)),
onPopToRuns: () {},
onPopToChat: () {},
cupertino: false,
initial: root,
);
addTearDown(router.dispose);
await tester.pumpWidget(
MaterialApp.router(
routerDelegate: router,
routeInformationParser: const AppRouteParser(),
routeInformationProvider: PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(
uri: Uri.parse(root.path),
),
),
),
);
await tester.pumpAndSettle();
expect(await router.popRoute(), isTrue);
await tester.pumpAndSettle();
expect(find.text('Press back again to close'), findsOneWidget);
expect(await router.popRoute(), isFalse);
await tester.pump(const Duration(seconds: 2));
await tester.pumpAndSettle();
expect(await router.popRoute(), isTrue);
await tester.pump();
router.goTo(AppRoute.pipeline(7));
await tester.pumpAndSettle();
expect(await router.popRoute(), isTrue);
await tester.pumpAndSettle();
expect(router.route, AppRoute.pipelines);
expect(find.text('Press back again to close'), findsNothing);
expect(await router.popRoute(), isTrue);
await tester.pumpAndSettle();
expect(find.text('Press back again to close'), findsOneWidget);
// Imperative dialogs also clear an already armed root exit.
final navigator = tester.state<NavigatorState>(find.byType(Navigator));
showDialog<void>(
context: navigator.overlay!.context,
builder: (_) => const AlertDialog(title: Text('Root dialog')),
);
await tester.pumpAndSettle();
expect(await router.popRoute(), isTrue);
await tester.pumpAndSettle();
expect(find.text('Root dialog'), findsNothing);
expect(await router.popRoute(), isTrue);
await tester.pumpAndSettle();
expect(await router.popRoute(), isFalse);
// Switching tabs or applying a platform/browser route re-arms exit too.
router.goTo(AppRoute.settings);
await tester.pumpAndSettle();
expect(await router.popRoute(), isTrue);
await tester.pumpAndSettle();
await router.setNewRoutePath(AppRoute.chat);
await tester.pumpAndSettle();
expect(await router.popRoute(), isTrue);
await tester.pump(const Duration(seconds: 3));
await tester.pumpWidget(const SizedBox.shrink());
});
}
test('iOS root Back is not intercepted', () async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
addTearDown(() => debugDefaultTargetPlatformOverride = null);
final router = delegate(AppRoute.pipelines);
addTearDown(router.dispose);
expect(await router.popRoute(), isFalse);
expect(await router.popRoute(), isFalse);
});
@@ -34,7 +34,7 @@ void main() {
for (final predictive in [false, true]) {
for (final destination in ['pipelines', 'runs', 'chat']) {
testWidgets(
'$destination: ${predictive ? 'gesture' : 'button'} Back pops dialog, detail, then app',
'$destination: ${predictive ? 'gesture' : 'button'} Back pops dialog, detail, then double-back exits',
(tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
@@ -136,7 +136,20 @@ void main() {
expect(navigator.canPop(), isFalse);
expect(exits, isEmpty);
// No confirmation, double-back requirement, or hidden detail route.
// A detail pop never arms root exit. The first root Back only hints.
if (predictive) {
await backGesture(tester, 'startBackGesture');
await backGesture(tester, 'cancelBackGesture');
await tester.pumpAndSettle();
expect(find.text('Press back again to close'), findsNothing);
await backGesture(tester, 'startBackGesture');
await backGesture(tester, 'commitBackGesture');
} else {
await tester.binding.handlePopRoute();
}
await tester.pumpAndSettle();
expect(exits, isEmpty);
expect(find.text('Press back again to close'), findsOneWidget);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(exits, ['SystemNavigator.pop']);
+5 -1
View File
@@ -213,7 +213,11 @@ void main() {
expect(provider.value.uri.path, '/runs');
expect(exits, isEmpty);
// From the list, Back is left to Android. No custom exit dialog.
// From the list, the first Back hints; the second is left to Android.
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(exits, isEmpty);
expect(find.text('Press back again to close'), findsOneWidget);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(find.text('Close Pipelines?'), findsNothing);