diff --git a/packages/flutter/lib/src/scheduler/binding.dart b/packages/flutter/lib/src/scheduler/binding.dart index fbd9215fc8..142acba7eb 100644 --- a/packages/flutter/lib/src/scheduler/binding.dart +++ b/packages/flutter/lib/src/scheduler/binding.dart @@ -338,6 +338,11 @@ mixin SchedulerBinding on BindingBase, ServicesBinding { } Future _handleLifecycleMessage(String message) async { + // TODO(chunhtai): remove the workaround once the issue is fixed + // https://github.com/flutter/flutter/issues/39832 + if (message == 'AppLifecycleState.detached') + return null; + handleAppLifecycleStateChanged(_parseAppLifecycleMessage(message)); return null; } diff --git a/packages/flutter/test/widgets/binding_test.dart b/packages/flutter/test/widgets/binding_test.dart index 6f9f9b7ca9..4ea8a65e24 100644 --- a/packages/flutter/test/widgets/binding_test.dart +++ b/packages/flutter/test/widgets/binding_test.dart @@ -67,6 +67,14 @@ void main() { message = const StringCodec().encodeMessage('AppLifecycleState.inactive'); await defaultBinaryMessenger.handlePlatformMessage('flutter/lifecycle', message, (_) { }); expect(observer.lifecycleState, AppLifecycleState.inactive); + + + message = const StringCodec().encodeMessage('AppLifecycleState.detached'); + await defaultBinaryMessenger.handlePlatformMessage('flutter/lifecycle', message, (_) { }); + // TODO(chunhtai): this should be detached once the issue is fixed + // https://github.com/flutter/flutter/issues/39832 + // The binding drops detached message for now. + expect(observer.lifecycleState, AppLifecycleState.inactive); }); testWidgets('didPushRoute callback', (WidgetTester tester) async {