Skip to content

Commit f2b02d8

Browse files
[iOS] Fixes text input plugin crash (flutter#20127)
1 parent e9334c9 commit f2b02d8

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ - (void)dealloc {
387387
}
388388

389389
- (UITextField*)textField {
390-
if (_textField == nil) {
391-
_textField = [[[UITextField alloc] init] autorelease];
390+
if (!_textField) {
391+
_textField = [[UITextField alloc] init];
392392
}
393393
return _textField;
394394
}

shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ - (void)setTextInputState:(NSDictionary*)state;
1717
- (BOOL)isVisibleToAutofill;
1818
@end
1919

20+
@interface FlutterSecureTextInputView : FlutterTextInputView
21+
@property(nonatomic, strong) UITextField* textField;
22+
@end
23+
2024
@interface FlutterTextInputPlugin ()
2125
@property(nonatomic, strong) FlutterTextInputView* reusableInputView;
2226
@property(nonatomic, assign) FlutterTextInputView* activeView;
@@ -496,4 +500,15 @@ - (void)testUITextInputCallsUpdateEditingStateOnce {
496500
[inputView unmarkText];
497501
XCTAssertEqual(updateCount, 6);
498502
}
503+
504+
- (void)testNoZombies {
505+
// Regression test for https://github.com/flutter/flutter/issues/62501.
506+
FlutterSecureTextInputView* passwordView = [[FlutterSecureTextInputView alloc] init];
507+
508+
@autoreleasepool {
509+
// Initialize the lazy textField.
510+
[passwordView.textField description];
511+
}
512+
XCTAssert([[passwordView.textField description] containsString:@"TextField"]);
513+
}
499514
@end

0 commit comments

Comments
 (0)