Skip to content

Commit 995a1da

Browse files
authored
Android predictive back should work after returning to the app from a notification (#154313)
Fixes a bug where the app would exit on a back gesture when there were still routes in the navigation stack after returning to the app from a notification.
1 parent 357704a commit 995a1da

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

packages/flutter/lib/src/widgets/app.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,9 +1368,9 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
13681368
switch (_appLifecycleState) {
13691369
case null:
13701370
case AppLifecycleState.detached:
1371-
case AppLifecycleState.inactive:
13721371
// Avoid updating the engine when the app isn't ready.
13731372
return true;
1373+
case AppLifecycleState.inactive:
13741374
case AppLifecycleState.resumed:
13751375
case AppLifecycleState.hidden:
13761376
case AppLifecycleState.paused:

packages/flutter/test/widgets/app_test.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -766,24 +766,26 @@ void main() {
766766
await tester.pumpAndSettle();
767767
expect(frameworkHandlesBacks.last, isFalse);
768768

769-
// Set the app state to inactive, where setFrameworkHandlesBack shouldn't
770-
// be called.
769+
// Set the app state to inactive, where setFrameworkHandlesBack is still
770+
// called. This could happen when responding to a tap on a notification
771+
// when the app is not active and immediately navigating, for example.
772+
// See https://github.com/flutter/flutter/pull/154313.
771773
await setAppLifeCycleState(AppLifecycleState.inactive);
772774

773-
final int finalCallsLength = frameworkHandlesBacks.length;
775+
final int inactiveStartCallsLength = frameworkHandlesBacks.length;
774776
const NavigationNotification(canHandlePop: true).dispatch(currentContext);
775777
await tester.pumpAndSettle();
776-
expect(frameworkHandlesBacks, hasLength(finalCallsLength));
778+
expect(frameworkHandlesBacks, hasLength(inactiveStartCallsLength + 1));
777779

778780
const NavigationNotification(canHandlePop: false).dispatch(currentContext);
779781
await tester.pumpAndSettle();
780-
expect(frameworkHandlesBacks, hasLength(finalCallsLength));
782+
expect(frameworkHandlesBacks, hasLength(inactiveStartCallsLength + 2));
781783

782-
// Set the app state to detached, which also shouldn't call
783-
// setFrameworkHandlesBack. Must go to paused, then detached.
784-
await setAppLifeCycleState(AppLifecycleState.paused);
784+
// Set the app state to detached, where setFrameworkHandlesBack shouldn't
785+
// be called.
785786
await setAppLifeCycleState(AppLifecycleState.detached);
786787

788+
final int finalCallsLength = frameworkHandlesBacks.length;
787789
const NavigationNotification(canHandlePop: true).dispatch(currentContext);
788790
await tester.pumpAndSettle();
789791
expect(frameworkHandlesBacks, hasLength(finalCallsLength));

0 commit comments

Comments
 (0)