Skip to content

Fix: TextInputAction not updating on keyboard when changed dynamically (fixes #185466) - #185582

Open
Istiak-Ahmed78 wants to merge 21 commits into
flutter:masterfrom
Istiak-Ahmed78:textfield-action
Open

Istiak-Ahmed78 wants to merge 21 commits into
flutter:masterfrom
Istiak-Ahmed78:textfield-action

Conversation

@Istiak-Ahmed78

@Istiak-Ahmed78 Istiak-Ahmed78 commented Apr 25, 2026 •

Copy link
Copy Markdown
Contributor

This PR fixes(#185466) a bug where the keyboard's action button (e.g., "Done", "Send") does not update in real-time when the textInputAction property changes on an EditableText widget, particularly on Android.

Problem

When textInputAction changes dynamically (e.g., from TextInputAction.done to TextInputAction.send), the Flutter framework detects the change but fails to notify the platform's Input Method Manager (IME) to refresh the keyboard button. The button only updates after the user interacts with it or the text input connection is manually recreated.

Solution

Modified the didUpdateWidget method in EditableTextState to:

  1. Detect when textInputAction changes
  2. Restart the input connection when textInputAction changes (instead of just calling updateConfig())
  3. This forces Android's InputMethodManager to completely reinitialize the keyboard with the new action

Code Changes

File: packages/flutter/lib/src/widgets/editable_text.dart

Method: EditableTextState.didUpdateWidget()

Before:

if (_hasInputConnection) {
  final obscureTextChanged = oldWidget.obscureText != widget.obscureText;
  if (obscureTextChanged || oldWidget.keyboardType != widget.keyboardType) {
    if (obscureTextChanged) {
      _obscureShowCharTicksPending = 0;
      _obscureLatestCharIndex = null;
    }
    _textInputConnection!.updateConfig(_effectiveAutofillClient.textInputConfiguration);
  }
}

After:

if (_hasInputConnection) {
  final obscureTextChanged = oldWidget.obscureText != widget.obscureText;
  final keyboardTypeChanged = oldWidget.keyboardType != widget.keyboardType;
  final textInputActionChanged = oldWidget.textInputAction != widget.textInputAction;

  if (obscureTextChanged || keyboardTypeChanged || textInputActionChanged) {
    if (obscureTextChanged) {
      _obscureShowCharTicksPending = 0;
      _obscureLatestCharIndex = null;
    }
    
    // If textInputAction changed, restart the connection to force IME refresh
    if (textInputActionChanged) {
      _scheduleRestartConnection();
    } else {
      _textInputConnection!.updateConfig(_effectiveAutofillClient.textInputConfiguration);
    }
  }
}
Screen_Recording_20260426_001524.mp4

Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. labels Apr 25, 2026
@Istiak-Ahmed78
Istiak-Ahmed78 marked this pull request as ready for review April 25, 2026 20:14

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies EditableTextState to handle changes in textInputAction by attempting to restart the input connection. However, the code calls _scheduleRestartConnection(), which is not defined in the current scope and will result in a compilation error. Additionally, the new test case should be updated to verify the configuration sent to the platform's text input instead of only asserting local state changes.


// If textInputAction changed, restart the connection to force IME refresh
if (textInputActionChanged) {
_scheduleRestartConnection();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The method _scheduleRestartConnection() is not defined in EditableTextState and is not included in this pull request. This will result in a compilation error.

If the intention is to force a full restart of the input connection (which is often necessary on Android to update the IME action button), you should ensure the method is defined or use an existing mechanism to restart the connection. Note that _openInputConnection() alone will only call updateConfig if a connection already exists.

Comment on lines +18594 to +18606
expect(currentAction, equals(TextInputAction.done));

// Type text: action changes to "send"
await tester.enterText(find.byType(TextField), 'hello');
await tester.pumpAndSettle();
expect(controller.text, equals('hello'));
expect(currentAction, equals(TextInputAction.send));

// Clear text: action changes back to "done"
await tester.enterText(find.byType(TextField), '');
await tester.pumpAndSettle();
expect(controller.text, isEmpty);
expect(currentAction, equals(TextInputAction.done));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This test does not actually verify that the TextField (or the underlying EditableText) updated the keyboard's configuration. It only asserts that the local currentAction variable in the test's state was updated by the onChanged callback.

To properly verify the fix, you should check the configuration sent to the platform via tester.testTextInput.configuration. This ensures that the framework actually communicated the change to the IME.

      expect(tester.testTextInput.configuration['inputAction'], equals(TextInputAction.done.toString()));

      // Type text: action changes to "send"
      await tester.enterText(find.byType(TextField), 'hello');
      await tester.pumpAndSettle();
      expect(controller.text, equals('hello'));
      expect(tester.testTextInput.configuration['inputAction'], equals(TextInputAction.send.toString()));

      // Clear text: action changes back to "done"
      await tester.enterText(find.byType(TextField), '');
      await tester.pumpAndSettle();
      expect(controller.text, isEmpty);
      expect(tester.testTextInput.configuration['inputAction'], equals(TextInputAction.done.toString()));
References
  1. Verify test validity: Confirm that new or modified tests effectively catch the issue being fixed and would fail if the fix were reverted. (link)

@Istiak-Ahmed78

Istiak-Ahmed78 commented Apr 25, 2026 •

Copy link
Copy Markdown
Contributor Author

I added a simple test TextField updates textInputAction when text changes there. But the test honestly does not verify textInputAction updates. I need suggestion from you. Is there any way to test action button on the keyboard? I did not find any reliable solution on the web. even though the gemini bot suggested a way.


// Initial: empty, "done"
expect(controller.text, isEmpty);
expect(currentAction, equals(TextInputAction.done));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test never validates that the text input connection is restarted when needed? It only validates if a local variable is set in the test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed it

),
);

await tester.tap(find.byType(EditableText));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't tap bring up the keyboard? Does the test still pass if you omit await tester.showKeyboard(find.byType(EditableText)); ?

@Istiak-Ahmed78 Istiak-Ahmed78 Apr 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@navaronbracke I ran the tests without this: await tester.showKeyboard(find.byType(EditableText)); . All tests passes. Now. Shall I remove the line? This line basically can be used cases like disappear or appear keyboard. But the test actually works without this. await tester.tap(find.byType(EditableText)); should invoke the keyboard.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I don't think tester.showKeyboard() is needed in this case, because of this reason

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I don't think tester.showKeyboard() is needed in this case, because of this reason

Removed

@Istiak-Ahmed78

Copy link
Copy Markdown
Contributor Author

Hi @navaronbracke , can you please review it? I made the changes you requested

style: const TextStyle(),
cursorColor: Color(0xFF0000FF),
backgroundCursorColor: Color(0xFF0A0A0A),
backgroundCursorColor: Colors.grey,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THis line still references Colors

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I'll fix it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THis line still references Colors

I've fixed that

),
);

await tester.tap(find.byType(EditableText));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I don't think tester.showKeyboard() is needed in this case, because of this reason

navaronbracke
navaronbracke previously approved these changes May 3, 2026
@Istiak-Ahmed78

Istiak-Ahmed78 commented May 3, 2026 •

Copy link
Copy Markdown
Contributor Author

@navaronbracke , this PR requires approval from another reviewer. Can you please add one?

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a bug using Chinese text composition on a Linux machine. This bug won't appear on Android using Gboard's Chinese input because it doesn the composition inside the keyboard and not in the Flutter TextField. Other IMEs and platforms may also suffer from this problem though.


// If textInputAction changed, restart the connection to force IME refresh
if (textInputActionChanged) {
_scheduleRestartConnection();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restarting the connection will break any in-progress CJK text composition. In the example from the issue for example:

master

Typing "nihao" then "1" to select the characters, then repeating the same thing again. Using a Chinese IME on Linux on master:

input_master.mp4

textfield-action

Same but on this branch instead of master:

input_istiak.mp4

Comment on lines +18568 to +18571
final controller = TextEditingController();
final focusNode = FocusNode();
addTearDown(controller.dispose);
addTearDown(focusNode.dispose);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nit: I would put the teardown of the controller immediately after its instantiation and before the instantiation of the FocusNode, just to be safe in case the FocusNode instantiation somehow threw an error.

@Istiak-Ahmed78

Copy link
Copy Markdown
Contributor Author

@justinmc , I don't own Linux Operating system, perhaps I can't test this in my machine. Can you share me any suggestion? Otherwise I may need to close this PR unfortunately

@justinmc

justinmc commented May 5, 2026

Copy link
Copy Markdown
Contributor

@Istiak-Ahmed78 You can likely reproduce it with a Chinese IME on any other desktop platform. What I'm doing in the videos is typing "nihao" then choosing the first option it gives me for the Chinese characters, which should be "你好", and then doing it again a second time. Also, I can reproduce the bug on iOS, though it manifests slightly differently:

Screen.Recording.2026-05-05.at.11.01.57.AM.mov

@justinmc
justinmc requested a review from Renzo-Olivares May 5, 2026 22:29
@AbdeMohlbi

AbdeMohlbi commented May 6, 2026 •

Copy link
Copy Markdown
Member

The linked issue was reported on both android and ios and this change presumably fixes the android side so the description should not say fixes that issue because it does not fix both platforms.

@Istiak-Ahmed78

Copy link
Copy Markdown
Contributor Author

The linked issue was reported on both android and ios and this change presumably fixes the android side so the description should not say fixes that issue because it does not fix both platforms.

As the issue is identical in both android & iOS. My fix was changes in platform side. So it should fix both Android & iOS. My changes don't include java side changes

@Istiak-Ahmed78

Istiak-Ahmed78 commented May 7, 2026 •

Copy link
Copy Markdown
Contributor Author

@Istiak-Ahmed78 You can likely reproduce it with a Chinese IME on any other desktop platform. What I'm doing in the videos is typing "nihao" then choosing the first option it gives me for the Chinese characters, which should be "你好", and then doing it again a second time. Also, I can reproduce the bug on iOS, though it manifests slightly differently:

Screen.Recording.2026-05-05.at.11.01.57.AM.mov

@justinmc, I dont own iOS, Mac or Linux. I tried to reproduce the issue on my physical android device

Screen_Recording_20260506_200840.mp4

But possibly I don't see such issue on andriod platform. I typed "nihao" with chinese language selected.

Whatever, I found some puzzling findings:

  • the keyboard action button changes correctly when the connection is created initially or closed-created (when user refocuses). But when user is typing something, the connection stays open, the input configuration is correctly sent to the platforms. From debug print:
[        ] I/flutter (30756): _configurationToJson: inputAction = TextInputAction.send
[        ] I/flutter (30756): _configurationToJson: Full JSON = {viewId: 0, inputType: {name: TextInputType.text, signed: null, decimal: null},
readOnly: false, obscureText: false, autocorrect: true, smartDashesType: 1, smartQuotesType: 1, enableSuggestions: true, enableInteractiveSelection:
true, actionLabel: null, inputAction: TextInputAction.send, textCapitalization: TextCapitalization.none, keyboardAppearance: Brightness.light,
enableIMEPersonalizedLearning: true, contentCommitMimeTypes: [], autofill: {uniqueIdentifier: EditableText-574617319, hints: [], editingValue: {text:f, selectionBase: 1, selectionExtent: 1, selectionAffinity: TextAffinity.downstream, selectionIsDirectional: false, composingBase: -1,
composingExtent: -1}}, enableDeltaModel: false, hintLocales: null, enableInlinePrediction: null}

from the logs we see the flutter is sending correct data to engine side through the method channel, but the soft keyboard is not responding to the configuration update. If this happens, so the problem could be in any specific platform (i.e only android or iOS) . But The bold question is:

Why is this happening in both platforms (Andorid & iOS)?

@justinmc , the problem you noticed about the chinese typing may not due to my changes. Why I'm saying that?
Look at my changes

 if (textInputActionChanged) {
          _scheduleRestartConnection();

   } else {
          _textInputConnection!.updateConfig(_effectiveAutofillClient.textInputConfiguration);
  }

I'm restarting the connection only when the textAction changes, for example first letter typed or user cleared the text field.

Same but on this branch instead of master:
https://github.com/user-attachments/assets/bbe6192f-b8bf-42f3-96f8-f0d1b9af55a3

I see here the text inputed changes unexpectedly even when my changes are not triggering. I suspect the problem may originate from changes from other contributor as my branch is not up to date with master

@Istiak-Ahmed78

Istiak-Ahmed78 commented May 7, 2026 •

Copy link
Copy Markdown
Contributor Author

It may appear as off topic (I'm sorry about that). But I dont understand where to ask.

I was having an issue. I can't build Android engine on Windows also found this in flutter doc.

Windows doesn't support cross-compiling artifacts for any of Android, Fuchsia, or iOS.

I made some changes in the engine side (java code). But from my investigation. I found I cannot work in such issues where modifications in engine side is required with my Windows operating system, this only can be done in Linux or macOS operating system. I ask for help or suggestion from anyone here . So is it not possible to work on such issues with my machine (Windows)?

@AbdeMohlbi

Copy link
Copy Markdown
Member

AFAIK, building from windows is not possible at the moment, so debugging this issue can be hard if you intend to change anything engine related.

@Istiak-Ahmed78

Istiak-Ahmed78 commented May 7, 2026 •

Copy link
Copy Markdown
Contributor Author

AFAIK, building from windows is not possible at the moment, so debugging this issue can be hard if you intend to change anything engine related.

Sad! But I think, windows machine should also be capable of doing such debugging. Do you know why it is not currently possible? I would like to know. Thank you for the response.

@AbdeMohlbi

Copy link
Copy Markdown
Member

i don't remember the exact cause tbh 😅, AFAIK you can build the windows engine and web variants from windows

@justinmc

Copy link
Copy Markdown
Contributor

If you install a Chinese IME on your Windows machine you'll probably be able to reproduce the bug. I was able to reproduce it by installing a Chinese IME (with a normal English hardware keyboard) on Linux.

But possibly I don't see such issue on andriod platform.

See #185582 (review) where I explain why the bug I mentioned doesn't happen on Android when using Gboard.

I'm restarting the connection only when the textAction changes

That's exactly when I'm seeing the bug happen when I used the example from the issue (#185466). That example changes the action after the first letter is typed, which is when I start to see mistakes in the composing text.

@navaronbracke
navaronbracke self-requested a review May 12, 2026 20:45
@justinmc justinmc added the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label May 21, 2026
@Istiak-Ahmed78

Copy link
Copy Markdown
Contributor Author

If you install a Chinese IME on your Windows machine you'll probably be able to reproduce the bug. I was able to reproduce it by installing a Chinese IME (with a normal English hardware keyboard) on Linux.

But possibly I don't see such issue on andriod platform.

See #185582 (review) where I explain why the bug I mentioned doesn't happen on Android when using Gboard.

I'm restarting the connection only when the textAction changes

That's exactly when I'm seeing the bug happen when I used the example from the issue (#185466). That example changes the action after the first letter is typed, which is when I start to see mistakes in the composing text.

Sorry for taking unexpected long time. I return to the track. Soon I'll address this

@github-actions github-actions Bot removed the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label May 27, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 3, 2026
@Istiak-Ahmed78

Istiak-Ahmed78 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Sorry for the late. Rebased onto master and pushed. The only conflict was in TextInputChannelTest.java

@AbdeMohlbi AbdeMohlbi added the CICD Run CI/CD label Nov 4, 2026

@LongCatIsLooong LongCatIsLooong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The framework / iOS implementation (barring the existing problem with updateConfig which isn't introduced in the PR) still lgtm.

@LongCatIsLooong

Copy link
Copy Markdown
Contributor

I'm syncing this to head to retry google testing.

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 19, 2026
@LongCatIsLooong LongCatIsLooong added the CICD Run CI/CD label Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems CICD Run CI/CD engine flutter/engine related. See also e: labels. framework flutter/packages/flutter repository. See also f: labels. platform-android Android applications specifically platform-ios iOS applications specifically team-android Owned by Android platform team team-ios Owned by iOS platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants