fix(app): restore standard Android back navigation
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Asks before Back leaves the app from the top of a tab. True to leave.
|
||||
Future<bool> confirmAppExit(
|
||||
BuildContext context, {
|
||||
required bool cupertino,
|
||||
}) async {
|
||||
const title = Text('Close Pipelines?');
|
||||
final leave = cupertino
|
||||
? await showCupertinoDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => CupertinoAlertDialog(
|
||||
title: title,
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
key: const Key('app-exit-stay'),
|
||||
isDefaultAction: true,
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: const Text('Stay'),
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
key: const Key('app-exit-close'),
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text('Close'),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: title,
|
||||
actions: [
|
||||
TextButton(
|
||||
key: const Key('app-exit-stay'),
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: const Text('Stay'),
|
||||
),
|
||||
FilledButton(
|
||||
key: const Key('app-exit-close'),
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text('Close'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return leave ?? false;
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'app_exit_dialog.dart';
|
||||
import 'app_route.dart';
|
||||
|
||||
/// Parses the browser (or platform) location into the app's routes.
|
||||
@@ -152,9 +149,9 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
_page(
|
||||
_pageKey,
|
||||
PopScope(
|
||||
canPop: !_canStepUp && !_asksBeforeExit,
|
||||
canPop: !_canStepUp,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop && !_stepUp()) _confirmExit();
|
||||
if (!didPop) _stepUp();
|
||||
},
|
||||
child: builder(context, shellRoute),
|
||||
),
|
||||
@@ -247,26 +244,7 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
return true;
|
||||
}
|
||||
if (_stepUp()) return true;
|
||||
return _confirmExit();
|
||||
}
|
||||
|
||||
/// At the top of a tab Android's Back would leave the app; ask first.
|
||||
/// Elsewhere (a browser) Back keeps its usual meaning.
|
||||
bool get _asksBeforeExit =>
|
||||
!kIsWeb && defaultTargetPlatform == TargetPlatform.android;
|
||||
|
||||
bool _confirming = false;
|
||||
|
||||
bool _confirmExit() {
|
||||
final context = _navigatorKey.currentContext;
|
||||
if (!_asksBeforeExit || context == null) return false;
|
||||
if (_confirming) return true;
|
||||
_confirming = true;
|
||||
confirmAppExit(context, cupertino: cupertino).then((leave) {
|
||||
_confirming = false;
|
||||
if (leave) SystemNavigator.pop();
|
||||
});
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Whether the open route has a level above it in its own tab (a stage,
|
||||
|
||||
Reference in New Issue
Block a user