From 0707b617d6819d7b4e5cf4f516c10bbd5c7d28ec Mon Sep 17 00:00:00 2001 From: Gao Di Date: Wed, 25 Dec 2024 18:04:56 +0800 Subject: [PATCH] On OHOS, disable components from listening to application focus changes. This prevents the app from actively hiding the keyboard after losing focus, as such operations are ineffective. --- packages/flutter/lib/src/widgets/focus_manager.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/widgets/focus_manager.dart b/packages/flutter/lib/src/widgets/focus_manager.dart index eb6eebf10b8..a02479a5ea5 100644 --- a/packages/flutter/lib/src/widgets/focus_manager.dart +++ b/packages/flutter/lib/src/widgets/focus_manager.dart @@ -1521,13 +1521,15 @@ class FocusManager with DiagnosticableTreeMixin, ChangeNotifier { if (kFlutterMemoryAllocationsEnabled) { ChangeNotifier.maybeDispatchObjectCreation(this); } - if (kIsWeb || defaultTargetPlatform != TargetPlatform.android) { + if (kIsWeb || (defaultTargetPlatform != TargetPlatform.android && defaultTargetPlatform != TargetPlatform.ohos)) { // It appears that some Android keyboard implementations can cause // app lifecycle state changes: adding this listener would cause the // text field to unfocus as the user is trying to type. // // Until this is resolved, we won't be adding the listener to Android apps. // https://github.com/flutter/flutter/pull/142930#issuecomment-1981750069 + // On the OHOS platform, any operations on the keyboard are ineffective when the app loses focus, + // making it unsuitable to listen to the application lifecycle. _appLifecycleListener = _AppLifecycleListener(_appLifecycleChange); WidgetsBinding.instance.addObserver(_appLifecycleListener!); } -- Gitee