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/cupertino.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../shell/list_detail.dart';
|
|
||||||
import 'android_root_exit.dart';
|
|
||||||
import 'app_route.dart';
|
import 'app_route.dart';
|
||||||
|
|
||||||
/// Parses the browser (or platform) location into the app's routes.
|
/// 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 {
|
class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||||
AppRouterDelegate({
|
AppRouterDelegate({
|
||||||
required this.builder,
|
required this.builder,
|
||||||
required this.onPopToRuns,
|
|
||||||
required this.onPopToChat,
|
|
||||||
required this.cupertino,
|
required this.cupertino,
|
||||||
this.searchBuilder,
|
this.searchBuilder,
|
||||||
this.templatesBuilder,
|
this.templatesBuilder,
|
||||||
@@ -76,17 +72,9 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
|||||||
/// state and selection, and the standard navigation bar supplies Back.
|
/// state and selection, and the standard navigation bar supplies Back.
|
||||||
final Widget Function(BuildContext context)? searchBuilder;
|
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 bool cupertino;
|
||||||
|
|
||||||
final _navigatorKey = GlobalKey<NavigatorState>();
|
final _navigatorKey = GlobalKey<NavigatorState>();
|
||||||
late final _rootExit = AndroidRootExit(notifyListeners);
|
|
||||||
static const _pageKey = ValueKey<String>('pipelines-shell');
|
static const _pageKey = ValueKey<String>('pipelines-shell');
|
||||||
static const _searchPageKey = ValueKey<String>('app-search');
|
static const _searchPageKey = ValueKey<String>('app-search');
|
||||||
static const _templatesPageKey = ValueKey<String>('app-templates');
|
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.
|
/// The destination that was open before Search, restored on close.
|
||||||
AppRoute _searchReturn;
|
AppRoute _searchReturn;
|
||||||
bool _searchTransient = false;
|
|
||||||
|
|
||||||
/// The Settings route the Templates page closes back to.
|
/// The Settings route the Templates page closes back to.
|
||||||
AppRoute _templatesReturn;
|
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
|
/// 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
|
/// remounting it and losing the open run. Search is the only extra page, so
|
||||||
/// its native Close action pops just that page.
|
/// 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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
_chatBesideList = showsListBesideDetail(context);
|
|
||||||
final searching = searchOpen && searchBuilder != null;
|
final searching = searchOpen && searchBuilder != null;
|
||||||
final templates = templatesOpen && templatesBuilder != null;
|
final templates = templatesOpen && templatesBuilder != null;
|
||||||
final schedules = schedulesOpen && schedulesBuilder != null;
|
final schedules = schedulesOpen && schedulesBuilder != null;
|
||||||
@@ -152,23 +134,8 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
|||||||
: _route;
|
: _route;
|
||||||
return Navigator(
|
return Navigator(
|
||||||
key: _navigatorKey,
|
key: _navigatorKey,
|
||||||
observers: [_rootExit],
|
|
||||||
pages: [
|
pages: [
|
||||||
// While an item is open inside its tab (a wide screen keeps it
|
_page(_pageKey, builder(context, shellRoute)),
|
||||||
// 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),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// Templates is a Settings sub-page: the shell stays mounted underneath,
|
// Templates is a Settings sub-page: the shell stays mounted underneath,
|
||||||
// so closing restores Settings exactly as it was left.
|
// so closing restores Settings exactly as it was left.
|
||||||
if (templates) _page(_templatesPageKey, templatesBuilder!(context)),
|
if (templates) _page(_templatesPageKey, templatesBuilder!(context)),
|
||||||
@@ -218,114 +185,40 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
|||||||
if (searchOpen) return;
|
if (searchOpen) return;
|
||||||
_searchReturn = _route;
|
_searchReturn = _route;
|
||||||
goTo(AppRoute.search);
|
goTo(AppRoute.search);
|
||||||
_searchTransient = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void closeSearch() {
|
void closeSearch() {
|
||||||
if (!searchOpen) return;
|
if (!searchOpen) return;
|
||||||
_searchTransient = false;
|
|
||||||
goTo(_searchReturn);
|
goTo(_searchReturn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> setInitialRoutePath(AppRoute configuration) async {
|
Future<void> setInitialRoutePath(AppRoute configuration) async {
|
||||||
_rootExit.clear();
|
|
||||||
_route = configuration;
|
_route = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> setNewRoutePath(AppRoute configuration) async {
|
Future<void> setNewRoutePath(AppRoute configuration) async {
|
||||||
if (configuration == _route) return;
|
if (configuration == _route) return;
|
||||||
_rootExit.clear();
|
|
||||||
_searchTransient = false;
|
|
||||||
_route = configuration;
|
_route = configuration;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Back (Android's button, the browser's): close whatever page sits on top
|
/// System Back is the Navigator's own: it pops the page on top (a pushed
|
||||||
/// first, then step up one level — a stage to its run or pipeline, a run,
|
/// detail, Search, Templates, Schedules or a dialog) and otherwise leaves
|
||||||
/// pipeline or chat to its list. Android list roots require two presses;
|
/// Back to the platform. The app adds no Back behavior of its own.
|
||||||
/// all other platforms retain their normal Back behavior.
|
|
||||||
@override
|
@override
|
||||||
Future<bool> popRoute() async {
|
Future<bool> popRoute() async =>
|
||||||
final navigator = _navigatorKey.currentState;
|
await _navigatorKey.currentState?.maybePop() ?? false;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Records a user move; the Router turns the new configuration into a
|
/// Records a user move; the Router turns the new configuration into a
|
||||||
/// history entry (or a replacement when it already matches the location).
|
/// history entry (or a replacement when it already matches the location).
|
||||||
void goTo(AppRoute route) {
|
void goTo(AppRoute route) {
|
||||||
if (route == _route) return;
|
if (route == _route) return;
|
||||||
_rootExit.clear();
|
|
||||||
_searchTransient = false;
|
|
||||||
_route = route;
|
_route = route;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_rootExit.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The location a launch starts at: the browser location on the web, the
|
/// The location a launch starts at: the browser location on the web, the
|
||||||
|
|||||||
@@ -177,8 +177,6 @@ class _PipelinesAppState extends State<PipelinesApp>
|
|||||||
_delegate = AppRouterDelegate(
|
_delegate = AppRouterDelegate(
|
||||||
initial: initial,
|
initial: initial,
|
||||||
cupertino: _cupertino,
|
cupertino: _cupertino,
|
||||||
onPopToRuns: () => _delegate.goTo(AppRoute.runs),
|
|
||||||
onPopToChat: () => _delegate.goTo(AppRoute.chat),
|
|
||||||
templatesBuilder: _buildTemplates,
|
templatesBuilder: _buildTemplates,
|
||||||
schedulesBuilder: _buildSchedules,
|
schedulesBuilder: _buildSchedules,
|
||||||
builder: _buildShell,
|
builder: _buildShell,
|
||||||
|
|||||||
@@ -201,16 +201,7 @@ class _TemplatesScreenState extends State<TemplatesScreen> {
|
|||||||
onBack: _back,
|
onBack: _back,
|
||||||
onRefresh: () => unawaited(_load()),
|
onRefresh: () => unawaited(_load()),
|
||||||
);
|
);
|
||||||
if (widget.embedded) return framed;
|
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,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A refused refresh stays visible above whichever body is current, so an
|
/// 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/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:pipelines_app/application/app_route.dart';
|
import 'package:pipelines_app/application/app_route.dart';
|
||||||
import 'package:pipelines_app/application/app_router.dart';
|
import 'package:pipelines_app/application/app_router.dart';
|
||||||
|
|
||||||
AppRouterDelegate delegate(AppRoute initial, {void Function()? onChat}) =>
|
AppRouterDelegate delegate(AppRoute initial) => AppRouterDelegate(
|
||||||
AppRouterDelegate(
|
builder: (context, route) => const SizedBox.shrink(),
|
||||||
builder: (context, route) => const SizedBox.shrink(),
|
cupertino: false,
|
||||||
onPopToRuns: () {},
|
initial: initial,
|
||||||
onPopToChat: onChat ?? () {},
|
);
|
||||||
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() {
|
void main() {
|
||||||
TestWidgetsFlutterBinding.ensureInitialized();
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
test(
|
test('with nothing pushed the router leaves Back to the platform', () async {
|
||||||
'router does not intercept chat Back or invoke the legacy override',
|
for (final route in [
|
||||||
() async {
|
AppRoute.pipelines,
|
||||||
var left = 0;
|
AppRoute.chat,
|
||||||
final router = delegate(AppRoute.chatSession('s1'), onChat: () => left++);
|
AppRoute.chatSession('s1'),
|
||||||
addTearDown(router.dispose);
|
AppRoute.run.stage(77, 'plan', visit: 0),
|
||||||
|
AppRoute.pipelineStage(4, 'plan', version: 2),
|
||||||
// With no Navigator mounted there is nothing to pop. The router must not
|
]) {
|
||||||
// substitute a chat-specific callback or arm main-screen double-back.
|
final router = delegate(route);
|
||||||
expect(await router.popRoute(), isFalse);
|
expect(await router.popRoute(), isFalse, reason: route.path);
|
||||||
expect(await router.popRoute(), isFalse);
|
expect(router.route, route, reason: route.path);
|
||||||
expect(left, 0);
|
router.dispose();
|
||||||
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(
|
|
||||||
'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 [
|
for (final root in [
|
||||||
AppRoute.pipelines,
|
AppRoute.pipelines,
|
||||||
AppRoute.runs,
|
AppRoute.run(7),
|
||||||
AppRoute.runsForPipeline(3),
|
|
||||||
AppRoute.chat,
|
AppRoute.chat,
|
||||||
AppRoute.settings,
|
AppRoute.settings,
|
||||||
AppRoute.search,
|
|
||||||
]) {
|
]) {
|
||||||
testWidgets('${root.path} root exit expires and navigation clears it', (
|
testWidgets('${root.path}: Back pops a dialog, then belongs to the '
|
||||||
tester,
|
'platform with no exit prompt or step-up', (tester) async {
|
||||||
) async {
|
final router = await pumpRouter(tester, root);
|
||||||
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));
|
final navigator = tester.state<NavigatorState>(find.byType(Navigator));
|
||||||
|
expect(
|
||||||
|
find.byWidgetPredicate((widget) => widget is PopScope),
|
||||||
|
findsNothing,
|
||||||
|
);
|
||||||
showDialog<void>(
|
showDialog<void>(
|
||||||
context: navigator.overlay!.context,
|
context: navigator.overlay!.context,
|
||||||
builder: (_) => const AlertDialog(title: Text('Root dialog')),
|
builder: (_) => const AlertDialog(title: Text('Root dialog')),
|
||||||
@@ -129,42 +74,28 @@ void main() {
|
|||||||
expect(await router.popRoute(), isTrue);
|
expect(await router.popRoute(), isTrue);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(find.text('Root dialog'), findsNothing);
|
expect(find.text('Root dialog'), findsNothing);
|
||||||
expect(await router.popRoute(), isTrue);
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
expect(await router.popRoute(), isFalse);
|
expect(await router.popRoute(), isFalse);
|
||||||
// Switching tabs or applying a platform/browser route re-arms exit too.
|
|
||||||
router.goTo(AppRoute.settings);
|
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(await router.popRoute(), isTrue);
|
expect(find.text('Press back again to close'), findsNothing);
|
||||||
await tester.pumpAndSettle();
|
expect(router.route, root);
|
||||||
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());
|
await tester.pumpWidget(const SizedBox.shrink());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
test('iOS root Back is not intercepted', () async {
|
testWidgets('Templates is a page above Settings and Back pops it', (
|
||||||
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
tester,
|
||||||
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
) async {
|
||||||
final router = delegate(AppRoute.pipelines);
|
final router = await pumpRouter(tester, AppRoute.settings);
|
||||||
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);
|
|
||||||
|
|
||||||
router.openTemplates();
|
router.openTemplates();
|
||||||
expect(router.route, AppRoute.templates);
|
await tester.pumpAndSettle();
|
||||||
expect(router.templatesOpen, isTrue);
|
expect(find.text('Templates page'), findsOneWidget);
|
||||||
|
|
||||||
expect(await router.popRoute(), isTrue);
|
expect(await router.popRoute(), isTrue);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
expect(router.route, AppRoute.settings);
|
expect(router.route, AppRoute.settings);
|
||||||
expect(router.templatesOpen, isFalse);
|
expect(router.templatesOpen, isFalse);
|
||||||
|
await tester.pumpWidget(const SizedBox.shrink());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('a /templates boot link still closes back to Settings', () async {
|
test('a /templates boot link still closes back to Settings', () async {
|
||||||
|
|||||||
@@ -73,8 +73,6 @@ void main() {
|
|||||||
router = AppRouterDelegate(
|
router = AppRouterDelegate(
|
||||||
initial: AppRoute.chat,
|
initial: AppRoute.chat,
|
||||||
cupertino: false,
|
cupertino: false,
|
||||||
onPopToChat: () => fail('Chat Back must not use the router override'),
|
|
||||||
onPopToRuns: () {},
|
|
||||||
builder: (_, route) => AdaptiveShell(
|
builder: (_, route) => AdaptiveShell(
|
||||||
destination: AppDestination.chat,
|
destination: AppDestination.chat,
|
||||||
destinationBodies: {
|
destinationBodies: {
|
||||||
@@ -155,14 +153,11 @@ void main() {
|
|||||||
expect(router.route, AppRoute.chat);
|
expect(router.route, AppRoute.chat);
|
||||||
expect(find.text('Scroll and return'), findsOneWidget);
|
expect(find.text('Scroll and return'), findsOneWidget);
|
||||||
expect(find.byKey(const ValueKey('chat-thread-s')), findsNothing);
|
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);
|
expect(exits, isEmpty);
|
||||||
|
// At the main screen Back is the platform's: no exit prompt.
|
||||||
await tester.binding.handlePopRoute();
|
await tester.binding.handlePopRoute();
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
|
expect(find.text('Press back again to close'), findsNothing);
|
||||||
expect(exits, ['SystemNavigator.pop']);
|
expect(exits, ['SystemNavigator.pop']);
|
||||||
await tester.pumpWidget(const SizedBox.shrink());
|
await tester.pumpWidget(const SizedBox.shrink());
|
||||||
disposeRouter();
|
disposeRouter();
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class _Gateway extends FakeChatGateway {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
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,
|
tester,
|
||||||
) async {
|
) async {
|
||||||
SharedPreferences.setMockInitialValues({});
|
SharedPreferences.setMockInitialValues({});
|
||||||
@@ -55,8 +55,6 @@ void main() {
|
|||||||
router = AppRouterDelegate(
|
router = AppRouterDelegate(
|
||||||
initial: AppRoute.chat,
|
initial: AppRoute.chat,
|
||||||
cupertino: false,
|
cupertino: false,
|
||||||
onPopToChat: () => fail('Chat Back must not use the router override'),
|
|
||||||
onPopToRuns: () {},
|
|
||||||
builder: (_, route) => AdaptiveShell(
|
builder: (_, route) => AdaptiveShell(
|
||||||
destination: AppDestination.chat,
|
destination: AppDestination.chat,
|
||||||
destinationBodies: {
|
destinationBodies: {
|
||||||
@@ -87,15 +85,11 @@ void main() {
|
|||||||
expect(router.route, AppRoute.chatSession('s'));
|
expect(router.route, AppRoute.chatSession('s'));
|
||||||
expect(find.byKey(const ValueKey('chat-thread-s')), findsOneWidget);
|
expect(find.byKey(const ValueKey('chat-thread-s')), findsOneWidget);
|
||||||
|
|
||||||
// First Back arms the exit instead of closing the app at once.
|
// No page covers the shell and the app adds no Back behavior: the
|
||||||
await tester.binding.handlePopRoute();
|
// platform's own Back applies at once, with no exit prompt.
|
||||||
await tester.pumpAndSettle();
|
|
||||||
expect(find.text('Press back again to close'), findsOneWidget);
|
|
||||||
expect(exits, isEmpty);
|
|
||||||
expect(find.byKey(const ValueKey('chat-thread-s')), findsOneWidget);
|
|
||||||
|
|
||||||
await tester.binding.handlePopRoute();
|
await tester.binding.handlePopRoute();
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
|
expect(find.text('Press back again to close'), findsNothing);
|
||||||
expect(exits, ['SystemNavigator.pop']);
|
expect(exits, ['SystemNavigator.pop']);
|
||||||
await tester.pumpWidget(const SizedBox.shrink());
|
await tester.pumpWidget(const SizedBox.shrink());
|
||||||
router.dispose();
|
router.dispose();
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ void main() {
|
|||||||
for (final predictive in [false, true]) {
|
for (final predictive in [false, true]) {
|
||||||
for (final destination in ['pipelines', 'runs', 'chat']) {
|
for (final destination in ['pipelines', 'runs', 'chat']) {
|
||||||
testWidgets(
|
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) async {
|
||||||
tester.view.physicalSize = const Size(390, 844);
|
tester.view.physicalSize = const Size(390, 844);
|
||||||
tester.view.devicePixelRatio = 1;
|
tester.view.devicePixelRatio = 1;
|
||||||
@@ -137,22 +137,11 @@ void main() {
|
|||||||
expect(navigator.canPop(), isFalse);
|
expect(navigator.canPop(), isFalse);
|
||||||
expect(exits, isEmpty);
|
expect(exits, isEmpty);
|
||||||
|
|
||||||
// A detail pop never arms root exit. The first root Back only hints.
|
// At the main screen Back is the platform's own: one press leaves,
|
||||||
if (predictive) {
|
// with no exit prompt.
|
||||||
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.binding.handlePopRoute();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Press back again to close'), findsNothing);
|
||||||
expect(exits, ['SystemNavigator.pop']);
|
expect(exits, ['SystemNavigator.pop']);
|
||||||
expect(find.text('Close Pipelines?'), findsNothing);
|
expect(find.text('Close Pipelines?'), findsNothing);
|
||||||
final router =
|
final router =
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ void main() {
|
|||||||
expect(find.text('Deep-linked run'), findsWidgets);
|
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,
|
tester,
|
||||||
) async {
|
) async {
|
||||||
tester.view.physicalSize = const Size(1000, 800);
|
tester.view.physicalSize = const Size(1000, 800);
|
||||||
@@ -208,22 +208,13 @@ void main() {
|
|||||||
await replyDetail(tester, channel, 1);
|
await replyDetail(tester, channel, 1);
|
||||||
expect(provider.value.uri.path, '/runs/1');
|
expect(provider.value.uri.path, '/runs/1');
|
||||||
|
|
||||||
// The system Back button or gesture.
|
// A wide run sits in its tab, not on a pushed page, and the app adds no
|
||||||
await tester.binding.handlePopRoute();
|
// Back behavior: the system Back is the platform's at once.
|
||||||
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.
|
|
||||||
await tester.binding.handlePopRoute();
|
await tester.binding.handlePopRoute();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(exits, isEmpty);
|
expect(find.text('Press back again to close'), findsNothing);
|
||||||
expect(find.text('Press back again to close'), findsOneWidget);
|
|
||||||
await tester.binding.handlePopRoute();
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
expect(find.text('Close Pipelines?'), findsNothing);
|
|
||||||
expect(exits, ['SystemNavigator.pop']);
|
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', (
|
testWidgets('tabs and run selection update the route; browser Back pops it', (
|
||||||
|
|||||||
@@ -829,29 +829,24 @@ void main() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
test(
|
test('openSearch keeps the previous route and closing restores it', () async {
|
||||||
'openSearch keeps the previous route and system Back restores it',
|
final router = AppRouterDelegate(
|
||||||
() async {
|
builder: (context, route) => const SizedBox.shrink(),
|
||||||
final router = AppRouterDelegate(
|
cupertino: false,
|
||||||
builder: (context, route) => const SizedBox.shrink(),
|
initial: AppRoute.run(3),
|
||||||
onPopToRuns: () {},
|
);
|
||||||
onPopToChat: () {},
|
addTearDown(router.dispose);
|
||||||
cupertino: false,
|
|
||||||
initial: AppRoute.run(3),
|
|
||||||
);
|
|
||||||
addTearDown(router.dispose);
|
|
||||||
|
|
||||||
router.openSearch();
|
router.openSearch();
|
||||||
expect(router.route, AppRoute.search);
|
expect(router.route, AppRoute.search);
|
||||||
expect(router.searchOpen, isTrue);
|
expect(router.searchOpen, isTrue);
|
||||||
// Without a page builder Search is the shell's own tab.
|
// Without a page builder Search is the shell's own tab.
|
||||||
expect(router.shellRoute, AppRoute.search);
|
expect(router.shellRoute, AppRoute.search);
|
||||||
|
|
||||||
expect(await router.popRoute(), isTrue);
|
router.closeSearch();
|
||||||
expect(router.route, AppRoute.run(3));
|
expect(router.route, AppRoute.run(3));
|
||||||
expect(router.searchOpen, isFalse);
|
expect(router.searchOpen, isFalse);
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
test('the /search route is total and survives the parser', () {
|
test('the /search route is total and survives the parser', () {
|
||||||
expect(AppRoute.parse('/search'), AppRoute.search);
|
expect(AppRoute.parse('/search'), AppRoute.search);
|
||||||
|
|||||||
@@ -182,7 +182,9 @@ void main() {
|
|||||||
expect(find.byKey(templateDetailKey), findsNothing);
|
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(
|
final gateway = GalleryGateway(
|
||||||
(type, fields) async => templatesReply(galleryTemplates),
|
(type, fields) async => templatesReply(galleryTemplates),
|
||||||
);
|
);
|
||||||
@@ -192,11 +194,12 @@ void main() {
|
|||||||
expect(find.byKey(templateDetailKey), findsOneWidget);
|
expect(find.byKey(templateDetailKey), findsOneWidget);
|
||||||
expect(selectableSource('blank'), 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();
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.byKey(templateDetailKey), findsOneWidget);
|
||||||
expect(find.byKey(templatesGalleryKey), findsOneWidget);
|
|
||||||
expect(find.byKey(templateDetailKey), findsNothing);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('embedded use drops the app bar and keeps native detail back', (
|
testWidgets('embedded use drops the app bar and keeps native detail back', (
|
||||||
|
|||||||
Reference in New Issue
Block a user