fix(app): remove every app-level system Back override
This commit is contained in:
@@ -1,63 +0,0 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// A short, Android-only exit window. The second Back is left to the platform,
|
||||
/// including its predictive back-to-home animation, rather than forcing exit.
|
||||
class AndroidRootExit extends NavigatorObserver {
|
||||
AndroidRootExit(this.onChanged);
|
||||
|
||||
final VoidCallback onChanged;
|
||||
static const window = Duration(seconds: 2);
|
||||
Timer? _timer;
|
||||
ScaffoldFeatureController<SnackBar, SnackBarClosedReason>? _hint;
|
||||
bool _disposed = false;
|
||||
|
||||
bool get enabled =>
|
||||
!kIsWeb && defaultTargetPlatform == TargetPlatform.android;
|
||||
bool get armed => _timer?.isActive ?? false;
|
||||
|
||||
bool handleBack() {
|
||||
if (!enabled || armed) return false;
|
||||
_timer = Timer(window, () {
|
||||
_timer = null;
|
||||
onChanged();
|
||||
});
|
||||
final context = navigator?.context;
|
||||
if (context != null) {
|
||||
_hint = ScaffoldMessenger.maybeOf(context)?.showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Press back again to close'),
|
||||
duration: window,
|
||||
),
|
||||
);
|
||||
}
|
||||
onChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_timer?.cancel();
|
||||
_timer = null;
|
||||
_hint?.close();
|
||||
_hint = null;
|
||||
}
|
||||
|
||||
@override
|
||||
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
|
||||
if (previousRoute == null || !armed) return;
|
||||
// Dialogs and imperative detail routes do not change the URL. Invalidate
|
||||
// their exit window too, outside the Navigator's build/route flush.
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (_disposed) return;
|
||||
clear();
|
||||
onChanged();
|
||||
});
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
_timer?.cancel();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../shell/list_detail.dart';
|
||||
import 'android_root_exit.dart';
|
||||
import 'app_route.dart';
|
||||
|
||||
/// Parses the browser (or platform) location into the app's routes.
|
||||
@@ -46,8 +44,6 @@ String routeLocation(Uri uri) {
|
||||
class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
AppRouterDelegate({
|
||||
required this.builder,
|
||||
required this.onPopToRuns,
|
||||
required this.onPopToChat,
|
||||
required this.cupertino,
|
||||
this.searchBuilder,
|
||||
this.templatesBuilder,
|
||||
@@ -76,17 +72,9 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
/// state and selection, and the standard navigation bar supplies Back.
|
||||
final Widget Function(BuildContext context)? searchBuilder;
|
||||
|
||||
/// Called when a system Back belongs to the Runs detail, not the app stack.
|
||||
final VoidCallback onPopToRuns;
|
||||
|
||||
/// Legacy callback retained for callers; chat Back is owned by its Navigator
|
||||
/// route and never invokes this override.
|
||||
final VoidCallback onPopToChat;
|
||||
|
||||
final bool cupertino;
|
||||
|
||||
final _navigatorKey = GlobalKey<NavigatorState>();
|
||||
late final _rootExit = AndroidRootExit(notifyListeners);
|
||||
static const _pageKey = ValueKey<String>('pipelines-shell');
|
||||
static const _searchPageKey = ValueKey<String>('app-search');
|
||||
static const _templatesPageKey = ValueKey<String>('app-templates');
|
||||
@@ -96,7 +84,6 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
|
||||
/// The destination that was open before Search, restored on close.
|
||||
AppRoute _searchReturn;
|
||||
bool _searchTransient = false;
|
||||
|
||||
/// The Settings route the Templates page closes back to.
|
||||
AppRoute _templatesReturn;
|
||||
@@ -135,13 +122,8 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
/// page key is stable, so changing the route updates it in place instead of
|
||||
/// remounting it and losing the open run. Search is the only extra page, so
|
||||
/// its native Close action pops just that page.
|
||||
/// Whether the window shows an open chat beside its list rather than as a
|
||||
/// pushed page. Read in [build], so a resize rebuilds the Back policy.
|
||||
bool _chatBesideList = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_chatBesideList = showsListBesideDetail(context);
|
||||
final searching = searchOpen && searchBuilder != null;
|
||||
final templates = templatesOpen && templatesBuilder != null;
|
||||
final schedules = schedulesOpen && schedulesBuilder != null;
|
||||
@@ -152,23 +134,8 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
: _route;
|
||||
return Navigator(
|
||||
key: _navigatorKey,
|
||||
observers: [_rootExit],
|
||||
pages: [
|
||||
// While an item is open inside its tab (a wide screen keeps it
|
||||
// there), Android's Back and back gesture step up a level instead of
|
||||
// leaving the app: the shell tells the system it handles Back.
|
||||
_page(
|
||||
_pageKey,
|
||||
PopScope(
|
||||
canPop: !_canStepUp && !(_isExitRoot && !_rootExit.armed),
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop && !_stepUp() && _isExitRoot) {
|
||||
_rootExit.handleBack();
|
||||
}
|
||||
},
|
||||
child: builder(context, shellRoute),
|
||||
),
|
||||
),
|
||||
_page(_pageKey, builder(context, shellRoute)),
|
||||
// Templates is a Settings sub-page: the shell stays mounted underneath,
|
||||
// so closing restores Settings exactly as it was left.
|
||||
if (templates) _page(_templatesPageKey, templatesBuilder!(context)),
|
||||
@@ -218,114 +185,40 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
if (searchOpen) return;
|
||||
_searchReturn = _route;
|
||||
goTo(AppRoute.search);
|
||||
_searchTransient = true;
|
||||
}
|
||||
|
||||
void closeSearch() {
|
||||
if (!searchOpen) return;
|
||||
_searchTransient = false;
|
||||
goTo(_searchReturn);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setInitialRoutePath(AppRoute configuration) async {
|
||||
_rootExit.clear();
|
||||
_route = configuration;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setNewRoutePath(AppRoute configuration) async {
|
||||
if (configuration == _route) return;
|
||||
_rootExit.clear();
|
||||
_searchTransient = false;
|
||||
_route = configuration;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Back (Android's button, the browser's): close whatever page sits on top
|
||||
/// first, then step up one level — a stage to its run or pipeline, a run,
|
||||
/// pipeline or chat to its list. Android list roots require two presses;
|
||||
/// all other platforms retain their normal Back behavior.
|
||||
/// System Back is the Navigator's own: it pops the page on top (a pushed
|
||||
/// detail, Search, Templates, Schedules or a dialog) and otherwise leaves
|
||||
/// Back to the platform. The app adds no Back behavior of its own.
|
||||
@override
|
||||
Future<bool> popRoute() async {
|
||||
final navigator = _navigatorKey.currentState;
|
||||
if (navigator != null && await navigator.maybePop()) return true;
|
||||
if (searchOpen && (searchBuilder != null || _searchTransient)) {
|
||||
closeSearch();
|
||||
return true;
|
||||
}
|
||||
if (schedulesOpen) {
|
||||
closeSchedules();
|
||||
return true;
|
||||
}
|
||||
if (templatesOpen) {
|
||||
closeTemplates();
|
||||
return true;
|
||||
}
|
||||
if (_stepUp()) return true;
|
||||
if (_isExitRoot) return _rootExit.handleBack();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get _isExitRoot =>
|
||||
_rootExit.enabled &&
|
||||
// A phone's open chat is a pushed page with stock Back. Beside the list
|
||||
// it is no page at all, so the list root's double-back applies.
|
||||
(_route.chatSessionId == null || _chatBesideList) &&
|
||||
!_canStepUp &&
|
||||
switch (_route.kind) {
|
||||
AppRouteKind.pipelines ||
|
||||
AppRouteKind.runs ||
|
||||
AppRouteKind.chat ||
|
||||
AppRouteKind.settings => true,
|
||||
AppRouteKind.search => searchBuilder == null && !_searchTransient,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
/// Whether an inline run/pipeline detail needs the shell to step up. Chats
|
||||
/// always own a pushed route and use normal Navigator Back instead.
|
||||
bool get _canStepUp =>
|
||||
_route.runId != null ||
|
||||
(_route.kind == AppRouteKind.pipelines && _route.pipelineId != null);
|
||||
|
||||
/// Goes up one level: a stage to its run or pipeline, an item to its list.
|
||||
bool _stepUp() {
|
||||
final runId = _route.runId;
|
||||
if (runId != null && _route.stageKey != null) {
|
||||
goTo(AppRoute.run(runId));
|
||||
return true;
|
||||
}
|
||||
if (runId != null) {
|
||||
onPopToRuns();
|
||||
return true;
|
||||
}
|
||||
final pipelineId = _route.pipelineId;
|
||||
if (_route.kind == AppRouteKind.pipelines && pipelineId != null) {
|
||||
goTo(
|
||||
_route.stageKey != null
|
||||
? AppRoute.pipeline(pipelineId, version: _route.version)
|
||||
: AppRoute.pipelines,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Future<bool> popRoute() async =>
|
||||
await _navigatorKey.currentState?.maybePop() ?? false;
|
||||
|
||||
/// Records a user move; the Router turns the new configuration into a
|
||||
/// history entry (or a replacement when it already matches the location).
|
||||
void goTo(AppRoute route) {
|
||||
if (route == _route) return;
|
||||
_rootExit.clear();
|
||||
_searchTransient = false;
|
||||
_route = route;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_rootExit.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// The location a launch starts at: the browser location on the web, the
|
||||
|
||||
@@ -177,8 +177,6 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
_delegate = AppRouterDelegate(
|
||||
initial: initial,
|
||||
cupertino: _cupertino,
|
||||
onPopToRuns: () => _delegate.goTo(AppRoute.runs),
|
||||
onPopToChat: () => _delegate.goTo(AppRoute.chat),
|
||||
templatesBuilder: _buildTemplates,
|
||||
schedulesBuilder: _buildSchedules,
|
||||
builder: _buildShell,
|
||||
|
||||
@@ -201,16 +201,7 @@ class _TemplatesScreenState extends State<TemplatesScreen> {
|
||||
onBack: _back,
|
||||
onRefresh: () => unawaited(_load()),
|
||||
);
|
||||
if (widget.embedded) return framed;
|
||||
// A selected template is this screen's own page: native back returns to
|
||||
// the gallery instead of leaving the destination.
|
||||
return PopScope(
|
||||
canPop: selected == null,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop && _selectedKey != null) _back();
|
||||
},
|
||||
child: framed,
|
||||
);
|
||||
return framed;
|
||||
}
|
||||
|
||||
/// A refused refresh stays visible above whichever body is current, so an
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# No app Back overrides
|
||||
|
||||
User request (2026-10-24): "I don't want any overrides in the back button anymore."
|
||||
|
||||
## Removed
|
||||
|
||||
- Router root double-back ("Press back again to close", `AndroidRootExit`,
|
||||
deleted) and its root `PopScope`, including the wide-chat variant from 7bb95d46.
|
||||
- Router step-up: a stage to its run/pipeline and an inline run/pipeline to its
|
||||
list (`_stepUp`, `onPopToRuns`, `onPopToChat`).
|
||||
- Router-side closing of Search/Templates/Schedules: they are Navigator pages,
|
||||
so the stock pop closes them through `onDidRemovePage`.
|
||||
- The standalone Templates screen's step-back `PopScope` (the app mounts it
|
||||
embedded, so it never ran in the app).
|
||||
|
||||
`AppRouterDelegate.popRoute` is now only `Navigator.maybePop()`: it pops the top
|
||||
page or dialog, otherwise Back belongs to the platform (one press leaves).
|
||||
|
||||
## Consequences
|
||||
|
||||
- A wide-window run or pipeline open inside its tab is not a page, so system
|
||||
Back leaves the app; the on-screen Back in the bar still returns to the list.
|
||||
Same for a wide chat beside its list.
|
||||
- Kept: `PopScope(canPop: !_sending)` on dialogs and the server editor, which
|
||||
block dismissal only while a request is in flight.
|
||||
|
||||
## Evidence
|
||||
|
||||
Router, navigation, wide-run, chat, search and templates tests rewritten to assert
|
||||
stock Back; `flutter analyze` clean; full suite passes. No device verification.
|
||||
@@ -1,126 +1,71 @@
|
||||
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';
|
||||
|
||||
AppRouterDelegate delegate(AppRoute initial, {void Function()? onChat}) =>
|
||||
AppRouterDelegate(
|
||||
builder: (context, route) => const SizedBox.shrink(),
|
||||
onPopToRuns: () {},
|
||||
onPopToChat: onChat ?? () {},
|
||||
cupertino: false,
|
||||
initial: initial,
|
||||
);
|
||||
AppRouterDelegate delegate(AppRoute initial) => AppRouterDelegate(
|
||||
builder: (context, route) => const SizedBox.shrink(),
|
||||
cupertino: false,
|
||||
initial: initial,
|
||||
);
|
||||
|
||||
Future<AppRouterDelegate> pumpRouter(
|
||||
WidgetTester tester,
|
||||
AppRoute initial,
|
||||
) async {
|
||||
final router = AppRouterDelegate(
|
||||
builder: (_, route) => Scaffold(body: Text(route.path)),
|
||||
templatesBuilder: (_) => const Scaffold(body: Text('Templates page')),
|
||||
cupertino: false,
|
||||
initial: initial,
|
||||
);
|
||||
addTearDown(router.dispose);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse(initial.path)),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp.router(
|
||||
routerDelegate: router,
|
||||
routeInformationParser: const AppRouteParser(),
|
||||
routeInformationProvider: provider,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return router;
|
||||
}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
test(
|
||||
'router does not intercept chat Back or invoke the legacy override',
|
||||
() async {
|
||||
var left = 0;
|
||||
final router = delegate(AppRoute.chatSession('s1'), onChat: () => left++);
|
||||
addTearDown(router.dispose);
|
||||
|
||||
// With no Navigator mounted there is nothing to pop. The router must not
|
||||
// substitute a chat-specific callback or arm main-screen double-back.
|
||||
expect(await router.popRoute(), isFalse);
|
||||
expect(await router.popRoute(), isFalse);
|
||||
expect(left, 0);
|
||||
expect(router.route, AppRoute.chatSession('s1'));
|
||||
},
|
||||
);
|
||||
|
||||
test('system Back steps up one level at a time', () async {
|
||||
var runs = 0;
|
||||
final router = AppRouterDelegate(
|
||||
builder: (context, route) => const SizedBox.shrink(),
|
||||
onPopToRuns: () => runs++,
|
||||
onPopToChat: () {},
|
||||
cupertino: false,
|
||||
initial: AppRoute.run.stage(77, 'plan', visit: 0),
|
||||
);
|
||||
addTearDown(router.dispose);
|
||||
|
||||
// A stage returns to its run, then the run to the Runs list.
|
||||
expect(await router.popRoute(), isTrue);
|
||||
expect(router.route, AppRoute.run(77));
|
||||
expect(await router.popRoute(), isTrue);
|
||||
expect(runs, 1);
|
||||
|
||||
// A pipeline stage returns to its pipeline, then to the list, and the
|
||||
// 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('with nothing pushed the router leaves Back to the platform', () async {
|
||||
for (final route in [
|
||||
AppRoute.pipelines,
|
||||
AppRoute.chat,
|
||||
AppRoute.chatSession('s1'),
|
||||
AppRoute.run.stage(77, 'plan', visit: 0),
|
||||
AppRoute.pipelineStage(4, 'plan', version: 2),
|
||||
]) {
|
||||
final router = delegate(route);
|
||||
expect(await router.popRoute(), isFalse, reason: route.path);
|
||||
expect(router.route, route, reason: route.path);
|
||||
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.run(7),
|
||||
AppRoute.chat,
|
||||
AppRoute.settings,
|
||||
AppRoute.search,
|
||||
]) {
|
||||
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.
|
||||
testWidgets('${root.path}: Back pops a dialog, then belongs to the '
|
||||
'platform with no exit prompt or step-up', (tester) async {
|
||||
final router = await pumpRouter(tester, root);
|
||||
final navigator = tester.state<NavigatorState>(find.byType(Navigator));
|
||||
expect(
|
||||
find.byWidgetPredicate((widget) => widget is PopScope),
|
||||
findsNothing,
|
||||
);
|
||||
showDialog<void>(
|
||||
context: navigator.overlay!.context,
|
||||
builder: (_) => const AlertDialog(title: Text('Root dialog')),
|
||||
@@ -129,42 +74,28 @@ void main() {
|
||||
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));
|
||||
expect(find.text('Press back again to close'), findsNothing);
|
||||
expect(router.route, root);
|
||||
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);
|
||||
});
|
||||
|
||||
test('Templates opens above Settings and Back restores the route', () async {
|
||||
final router = delegate(AppRoute.settings);
|
||||
addTearDown(router.dispose);
|
||||
|
||||
testWidgets('Templates is a page above Settings and Back pops it', (
|
||||
tester,
|
||||
) async {
|
||||
final router = await pumpRouter(tester, AppRoute.settings);
|
||||
router.openTemplates();
|
||||
expect(router.route, AppRoute.templates);
|
||||
expect(router.templatesOpen, isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Templates page'), findsOneWidget);
|
||||
|
||||
expect(await router.popRoute(), isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
expect(router.route, AppRoute.settings);
|
||||
expect(router.templatesOpen, isFalse);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
test('a /templates boot link still closes back to Settings', () async {
|
||||
|
||||
@@ -73,8 +73,6 @@ void main() {
|
||||
router = AppRouterDelegate(
|
||||
initial: AppRoute.chat,
|
||||
cupertino: false,
|
||||
onPopToChat: () => fail('Chat Back must not use the router override'),
|
||||
onPopToRuns: () {},
|
||||
builder: (_, route) => AdaptiveShell(
|
||||
destination: AppDestination.chat,
|
||||
destinationBodies: {
|
||||
@@ -155,14 +153,11 @@ void main() {
|
||||
expect(router.route, AppRoute.chat);
|
||||
expect(find.text('Scroll and return'), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('chat-thread-s')), findsNothing);
|
||||
expect(find.text('Press back again to close'), findsNothing);
|
||||
expect(exits, isEmpty);
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Press back again to close'), findsOneWidget);
|
||||
expect(exits, isEmpty);
|
||||
// At the main screen Back is the platform's: no exit prompt.
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pump();
|
||||
expect(find.text('Press back again to close'), findsNothing);
|
||||
expect(exits, ['SystemNavigator.pop']);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
disposeRouter();
|
||||
|
||||
@@ -28,7 +28,7 @@ class _Gateway extends FakeChatGateway {
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('an open chat beside the list takes the root double-back', (
|
||||
testWidgets('an open chat beside the list leaves Back to the platform', (
|
||||
tester,
|
||||
) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
@@ -55,8 +55,6 @@ void main() {
|
||||
router = AppRouterDelegate(
|
||||
initial: AppRoute.chat,
|
||||
cupertino: false,
|
||||
onPopToChat: () => fail('Chat Back must not use the router override'),
|
||||
onPopToRuns: () {},
|
||||
builder: (_, route) => AdaptiveShell(
|
||||
destination: AppDestination.chat,
|
||||
destinationBodies: {
|
||||
@@ -87,15 +85,11 @@ void main() {
|
||||
expect(router.route, AppRoute.chatSession('s'));
|
||||
expect(find.byKey(const ValueKey('chat-thread-s')), findsOneWidget);
|
||||
|
||||
// First Back arms the exit instead of closing the app at once.
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Press back again to close'), findsOneWidget);
|
||||
expect(exits, isEmpty);
|
||||
expect(find.byKey(const ValueKey('chat-thread-s')), findsOneWidget);
|
||||
|
||||
// No page covers the shell and the app adds no Back behavior: the
|
||||
// platform's own Back applies at once, with no exit prompt.
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pump();
|
||||
expect(find.text('Press back again to close'), findsNothing);
|
||||
expect(exits, ['SystemNavigator.pop']);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
router.dispose();
|
||||
|
||||
@@ -35,7 +35,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 double-back exits',
|
||||
'$destination: ${predictive ? 'gesture' : 'button'} Back pops dialog, detail, then leaves to the platform',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
@@ -137,22 +137,11 @@ void main() {
|
||||
expect(navigator.canPop(), isFalse);
|
||||
expect(exits, isEmpty);
|
||||
|
||||
// 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);
|
||||
// At the main screen Back is the platform's own: one press leaves,
|
||||
// with no exit prompt.
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Press back again to close'), findsNothing);
|
||||
expect(exits, ['SystemNavigator.pop']);
|
||||
expect(find.text('Close Pipelines?'), findsNothing);
|
||||
final router =
|
||||
|
||||
@@ -171,7 +171,7 @@ void main() {
|
||||
expect(find.text('Deep-linked run'), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('Android Back on a wide screen steps out of a run, not the app', (
|
||||
testWidgets('Android Back on a wide screen run is left to the platform', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(1000, 800);
|
||||
@@ -208,22 +208,13 @@ void main() {
|
||||
await replyDetail(tester, channel, 1);
|
||||
expect(provider.value.uri.path, '/runs/1');
|
||||
|
||||
// The system Back button or gesture.
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pump();
|
||||
expect(provider.value.uri.path, '/runs');
|
||||
expect(exits, isEmpty);
|
||||
|
||||
// From the list, the first Back hints; the second is left to Android.
|
||||
// A wide run sits in its tab, not on a pushed page, and the app adds no
|
||||
// Back behavior: the system Back is the platform's at once.
|
||||
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);
|
||||
expect(find.text('Press back again to close'), findsNothing);
|
||||
expect(exits, ['SystemNavigator.pop']);
|
||||
expect(provider.value.uri.path, '/runs');
|
||||
expect(provider.value.uri.path, '/runs/1');
|
||||
});
|
||||
|
||||
testWidgets('tabs and run selection update the route; browser Back pops it', (
|
||||
|
||||
@@ -829,29 +829,24 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'openSearch keeps the previous route and system Back restores it',
|
||||
() async {
|
||||
final router = AppRouterDelegate(
|
||||
builder: (context, route) => const SizedBox.shrink(),
|
||||
onPopToRuns: () {},
|
||||
onPopToChat: () {},
|
||||
cupertino: false,
|
||||
initial: AppRoute.run(3),
|
||||
);
|
||||
addTearDown(router.dispose);
|
||||
test('openSearch keeps the previous route and closing restores it', () async {
|
||||
final router = AppRouterDelegate(
|
||||
builder: (context, route) => const SizedBox.shrink(),
|
||||
cupertino: false,
|
||||
initial: AppRoute.run(3),
|
||||
);
|
||||
addTearDown(router.dispose);
|
||||
|
||||
router.openSearch();
|
||||
expect(router.route, AppRoute.search);
|
||||
expect(router.searchOpen, isTrue);
|
||||
// Without a page builder Search is the shell's own tab.
|
||||
expect(router.shellRoute, AppRoute.search);
|
||||
router.openSearch();
|
||||
expect(router.route, AppRoute.search);
|
||||
expect(router.searchOpen, isTrue);
|
||||
// Without a page builder Search is the shell's own tab.
|
||||
expect(router.shellRoute, AppRoute.search);
|
||||
|
||||
expect(await router.popRoute(), isTrue);
|
||||
expect(router.route, AppRoute.run(3));
|
||||
expect(router.searchOpen, isFalse);
|
||||
},
|
||||
);
|
||||
router.closeSearch();
|
||||
expect(router.route, AppRoute.run(3));
|
||||
expect(router.searchOpen, isFalse);
|
||||
});
|
||||
|
||||
test('the /search route is total and survives the parser', () {
|
||||
expect(AppRoute.parse('/search'), AppRoute.search);
|
||||
|
||||
@@ -182,7 +182,9 @@ void main() {
|
||||
expect(find.byKey(templateDetailKey), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('native back returns to the gallery', (tester) async {
|
||||
testWidgets('system Back is not intercepted by the open template', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = GalleryGateway(
|
||||
(type, fields) async => templatesReply(galleryTemplates),
|
||||
);
|
||||
@@ -192,11 +194,12 @@ void main() {
|
||||
expect(find.byKey(templateDetailKey), findsOneWidget);
|
||||
expect(selectableSource('blank'), findsOneWidget);
|
||||
|
||||
await tester.binding.handlePopRoute();
|
||||
expect(find.byType(PopScope), findsNothing);
|
||||
// Nothing is pushed, so Back is the platform's; the screen keeps no
|
||||
// Back behavior of its own.
|
||||
expect(await tester.binding.handlePopRoute(), isFalse);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(templatesGalleryKey), findsOneWidget);
|
||||
expect(find.byKey(templateDetailKey), findsNothing);
|
||||
expect(find.byKey(templateDetailKey), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('embedded use drops the app bar and keeps native detail back', (
|
||||
|
||||
Reference in New Issue
Block a user