I’m using the html_editor_enhanced
package in my Flutter app to provide a rich text editor. I’m trying to programmatically focus the editor (auto-focus) when a screen opens. This works fine on Android, but auto focus doesn’t work on iOS.
Steps to Reproduce:
- Add
html_editor_enhanced
to your project. - Create an editor instance inside a screen.
- Call
controller.focus()
insideinitState()
orafterFirstLayout
. - Run the app on iOS.
Expected Behavior:
Editor should gain focus automatically, and the keyboard should open when the screen loads.
Actual Behavior (iOS):
Editor does not gain focus automatically. The keyboard doesn’t show up. User has to manually tap inside the editor to begin typing.
What I’ve Tried:
- Called
controller.focus()
after a delay. - Wrapped it in
WidgetsBinding.instance.addPostFrameCallback
. - Tried using JavaScript injection (
document.getElementsByClassName("note-editable")[0].focus();
) viacontroller.evaluateJavascript
. - Verified it works on Android but fails silently on iOS.