Repository navigation
Fix: TextInputAction not updating on keyboard when changed dynamically (fixes #185466) - #185582
Istiak-Ahmed78 wants to merge 21 commits into
Conversation
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
| 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)); |
There was a problem hiding this comment.
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
- Verify test validity: Confirm that new or modified tests effectively catch the issue being fixed and would fail if the fix were reverted. (link)
|
I added a simple test |
|
|
||
| // Initial: empty, "done" | ||
| expect(controller.text, isEmpty); | ||
| expect(currentAction, equals(TextInputAction.done)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
I've fixed it
| ), | ||
| ); | ||
|
|
||
| await tester.tap(find.byType(EditableText)); |
There was a problem hiding this comment.
Doesn't tap bring up the keyboard? Does the test still pass if you omit await tester.showKeyboard(find.byType(EditableText)); ?
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
Yes, I don't think tester.showKeyboard() is needed in this case, because of this reason
There was a problem hiding this comment.
Yes, I don't think
tester.showKeyboard()is needed in this case, because of this reason
Removed
|
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, |
There was a problem hiding this comment.
THis line still references Colors
There was a problem hiding this comment.
Got it. I'll fix it
There was a problem hiding this comment.
THis line still references
Colors
I've fixed that
| ), | ||
| ); | ||
|
|
||
| await tester.tap(find.byType(EditableText)); |
There was a problem hiding this comment.
Yes, I don't think tester.showKeyboard() is needed in this case, because of this reason
|
@navaronbracke , this PR requires approval from another reviewer. Can you please add one? |
justinmc
left a comment
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
| final controller = TextEditingController(); | ||
| final focusNode = FocusNode(); | ||
| addTearDown(controller.dispose); | ||
| addTearDown(focusNode.dispose); |
There was a problem hiding this comment.
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.
|
@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 |
|
@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 |
|
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 |
@justinmc, I dont own iOS, Mac or Linux. I tried to reproduce the issue on my physical android device Screen_Recording_20260506_200840.mp4But possibly I don't see such issue on andriod platform. I typed "nihao" with chinese language selected. Whatever, I found some puzzling findings:
[ ] 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? 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.
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 |
|
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.
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)? |
|
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. |
|
i don't remember the exact cause tbh 😅, AFAIK you can build the windows engine and web variants from windows |
|
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.
See #185582 (review) where I explain why the bug I mentioned doesn't happen on Android when using Gboard.
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 |
Co-authored-by: Navaron Bracke <[email protected]>
Co-authored-by: Navaron Bracke <[email protected]>
Co-authored-by: Navaron Bracke <[email protected]>
Co-authored-by: Navaron Bracke <[email protected]>
Co-authored-by: Navaron Bracke <[email protected]>
9d9d94f
6905455 to
9d9d94f
Compare
|
Sorry for the late. Rebased onto master and pushed. The only conflict was in |
LongCatIsLooong
left a comment
There was a problem hiding this comment.
The framework / iOS implementation (barring the existing problem with updateConfig which isn't introduced in the PR) still lgtm.
|
I'm syncing this to head to retry google testing. |
This PR fixes(#185466) a bug where the keyboard's action button (e.g., "Done", "Send") does not update in real-time when the
textInputActionproperty changes on anEditableTextwidget, particularly on Android.Problem
When
textInputActionchanges dynamically (e.g., fromTextInputAction.donetoTextInputAction.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
didUpdateWidgetmethod inEditableTextStateto:textInputActionchangestextInputActionchanges (instead of just callingupdateConfig())Code Changes
File:
packages/flutter/lib/src/widgets/editable_text.dartMethod:
EditableTextState.didUpdateWidget()Before:
After:
Screen_Recording_20260426_001524.mp4
Checklist
///).