diff --git a/packages/flutter/lib/src/widgets/app.dart b/packages/flutter/lib/src/widgets/app.dart index f2bd6273cf..88720bd71c 100644 --- a/packages/flutter/lib/src/widgets/app.dart +++ b/packages/flutter/lib/src/widgets/app.dart @@ -1368,9 +1368,9 @@ class _WidgetsAppState extends State with WidgetsBindingObserver { switch (_appLifecycleState) { case null: case AppLifecycleState.detached: - case AppLifecycleState.inactive: // Avoid updating the engine when the app isn't ready. return true; + case AppLifecycleState.inactive: case AppLifecycleState.resumed: case AppLifecycleState.hidden: case AppLifecycleState.paused: diff --git a/packages/flutter/test/widgets/app_test.dart b/packages/flutter/test/widgets/app_test.dart index 966fb3c125..3265decd67 100644 --- a/packages/flutter/test/widgets/app_test.dart +++ b/packages/flutter/test/widgets/app_test.dart @@ -766,24 +766,26 @@ void main() { await tester.pumpAndSettle(); expect(frameworkHandlesBacks.last, isFalse); - // Set the app state to inactive, where setFrameworkHandlesBack shouldn't - // be called. + // Set the app state to inactive, where setFrameworkHandlesBack is still + // called. This could happen when responding to a tap on a notification + // when the app is not active and immediately navigating, for example. + // See https://github.com/flutter/flutter/pull/154313. await setAppLifeCycleState(AppLifecycleState.inactive); - final int finalCallsLength = frameworkHandlesBacks.length; + final int inactiveStartCallsLength = frameworkHandlesBacks.length; const NavigationNotification(canHandlePop: true).dispatch(currentContext); await tester.pumpAndSettle(); - expect(frameworkHandlesBacks, hasLength(finalCallsLength)); + expect(frameworkHandlesBacks, hasLength(inactiveStartCallsLength + 1)); const NavigationNotification(canHandlePop: false).dispatch(currentContext); await tester.pumpAndSettle(); - expect(frameworkHandlesBacks, hasLength(finalCallsLength)); + expect(frameworkHandlesBacks, hasLength(inactiveStartCallsLength + 2)); - // Set the app state to detached, which also shouldn't call - // setFrameworkHandlesBack. Must go to paused, then detached. - await setAppLifeCycleState(AppLifecycleState.paused); + // Set the app state to detached, where setFrameworkHandlesBack shouldn't + // be called. await setAppLifeCycleState(AppLifecycleState.detached); + final int finalCallsLength = frameworkHandlesBacks.length; const NavigationNotification(canHandlePop: true).dispatch(currentContext); await tester.pumpAndSettle(); expect(frameworkHandlesBacks, hasLength(finalCallsLength));