diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 9358431cf5a6f..4531df7e182c8 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -2675,8 +2675,11 @@ - (void)hideTextInput { [self removeEnableFlutterTextInputViewAccessibilityTimer]; _activeView.accessibilityEnabled = NO; [_activeView resignFirstResponder]; - [_activeView removeFromSuperview]; - [_inputHider removeFromSuperview]; + // Removes the focus from the `_activeView` (UIView) + // when the user stops typing (keyboard is hidden). + // For more details, refer to the discussion at: + // https://github.com/flutter/engine/pull/57209#discussion_r1905942577 + [self cleanUpViewHierarchy:YES clearText:YES delayRemoval:NO]; } - (void)triggerAutofillSave:(BOOL)saveEntries { diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm index be00f6e1e63d4..46a2104164a2c 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm @@ -2691,6 +2691,27 @@ - (void)testInitialActiveViewCantAccessTextInputDelegate { XCTAssertNil(textInputPlugin.activeView.textInputDelegate); } +- (void)testAutoFillDoesNotTriggerOnHideButTriggersOnCommit { + // Regression test for https://github.com/flutter/flutter/issues/145681. + NSMutableDictionary* configuration = self.mutableTemplateCopy; + [configuration setValue:@{ + @"uniqueIdentifier" : @"field1", + @"hints" : @[ UITextContentTypePassword ], + @"editingValue" : @{@"text" : @""} + } + forKey:@"autofill"]; + [configuration setValue:@[ [configuration copy] ] forKey:@"fields"]; + + [self setClientId:123 configuration:configuration]; + XCTAssertEqual(self.viewsVisibleToAutofill.count, 1ul); + + [self setTextInputHide]; + // Before the fix in https://github.com/flutter/engine/pull/57209, it was 0ul. + XCTAssertEqual(self.viewsVisibleToAutofill.count, 1ul); + + [self commitAutofillContextAndVerify]; +} + #pragma mark - Accessibility - Tests - (void)testUITextInputAccessibilityNotHiddenWhenShowed {