Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onSubmitted with TextField when pressing Enter key #19027

Open
droidery opened this issue Jul 3, 2018 · 14 comments
Open

onSubmitted with TextField when pressing Enter key #19027

droidery opened this issue Jul 3, 2018 · 14 comments

Comments

@droidery
Copy link

@droidery droidery commented Jul 3, 2018

Steps to Reproduce

  1. Create a TextField with onSubmitted function
  2. Run app in Android simulator
  3. Press enter on keyboard
  4. onSubmitted is not called

Logs

Whenever you press Enter these come up in the error log:

W/IInputConnectionWrapper( 8999): getCursorCapsMode on inactive InputConnection
W/IInputConnectionWrapper( 8999): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 8999): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 8999): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 8999): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 8999): endBatchEdit on inactive InputConnection
[✓] Flutter (Channel master, v0.5.6-pre.121, on Mac OS X 10.13.5, locale en-US)
    • Flutter version 0.5.6-pre.121 at /Users/droider/flutter
    • Framework revision a4faa2e067 (85 minutes ago), 2018-07-02 16:35:43 -0700
    • Engine revision 6fe748490d
    • Dart version 2.0.0-dev.63.0.flutter-4c9689c1d2

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    • Android SDK at /Users/droider/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 27.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.4.1, Build version 9F2000
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.2

[✓] Android Studio (version 3.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 26.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[✓] Connected devices (1 available)
    • Android SDK built for x86 • emulator-5556 • android-x86 • Android P (API 27) (emulator)
@zoechi

This comment has been minimized.

Copy link
Contributor

@zoechi zoechi commented Jul 3, 2018

I'm not sure what the issue is about. What behavior do you expect?
Might be related to #9573 #17527 #18855

@zoechi zoechi added the a: text input label Jul 3, 2018
@droidery

This comment has been minimized.

Copy link
Author

@droidery droidery commented Jul 4, 2018

On iOS when you hit enter on the keyboard it submits the TextField and calls onSubmitted, but if you're on Android it doesn't submit when you press enter.

Shouldn't the behavior be consistent.

@code4ghana

This comment has been minimized.

Copy link

@code4ghana code4ghana commented Aug 25, 2018

void _handleSubmission(String text) {
// Not triggered when you press enter on keyboard in  android simulator
// Triggers if you tap on the Done button.
}
new TextField(
  maxLines: 1,
  onSubmitted: _handleSubmission)
@yuriry

This comment has been minimized.

Copy link

@yuriry yuriry commented Oct 26, 2018

Still running into this. The tutorial does not work on Android emulator.

@Jon-Salmon

This comment has been minimized.

Copy link

@Jon-Salmon Jon-Salmon commented Nov 23, 2018

I'm also running into this issue when a bluetooth keyboard is connected on android. On screen keyboard works fine but an external one does not.
I havn't tried an emulator.

@zoechi zoechi added this to the Goals milestone Nov 25, 2018
@zoechi

This comment has been minimized.

Copy link
Contributor

@zoechi zoechi commented Dec 19, 2018

Is this a duplicate of #15757 ?

@baeharam

This comment has been minimized.

Copy link

@baeharam baeharam commented Jan 27, 2019

Any implementation yet?

@jicg

This comment has been minimized.

Copy link

@jicg jicg commented Jul 3, 2019

how to handle the enter key ?

@MichealReed

This comment has been minimized.

Copy link

@MichealReed MichealReed commented Jul 7, 2019

Would be great if web is supported here as well.

@jicg

This comment has been minimized.

Copy link

@jicg jicg commented Jul 7, 2019

This topic has been a year... I don’t know when the gods can achieve it. . .

jkarelbroer added a commit to Unizer/unizer-mobile that referenced this issue Jul 19, 2019
Added onSubmit action in passwordfield
@Caizoo

This comment has been minimized.

Copy link

@Caizoo Caizoo commented Aug 3, 2019

Use a TextFormField and then you can set the onEditingComplete to then handle submission

@MichealReed

This comment has been minimized.

Copy link

@MichealReed MichealReed commented Aug 12, 2019

Wrap the page in a keyboard listener to achieve the same effect.

child: RawKeyboardListener(
                  focusNode: FocusNode(),
                  onKey: (event) {
                    //print(event.data.logicalKey.keyId);
                     /* if (event.runtimeType == RawKeyDownEvent &&
                          (event.logicalKey.keyId == 54)) {Navigator.pop(context, this._textController.text);} */
                    
                  },
                  child: TextFormField(
                    controller: _textController,
                    onFieldSubmitted: (_textController) {
                      Navigator.pop(context, this._textController.text);
                    },
                    ),
                  ),
@SystemTce

This comment has been minimized.

Copy link

@SystemTce SystemTce commented Nov 16, 2019

https://stackoverflow.com/a/58888683/12376696
I tried to capture the "enter key" in onChanged.

@dewball345

This comment has been minimized.

Copy link

@dewball345 dewball345 commented Dec 1, 2019

Hello there,
I actually had a similar problem as well! Here's my reasoning to why it works in that manner:
On an actual android phone, there is no actual enter key, just a "submit" button marked with a check. Therefore, the onSubmit function probably only gets called when the "check" button is pressed.

However, I really don't know why it works with iOS. Maybe it's just the way flutter works? Either way, it won't affect how your application works on a real device.

However, if you still want to use the "enter" key using your keyboard, you can follow Micheal Reed's answer:

Wrap the page in a keyboard listener to achieve the same effect.

child: RawKeyboardListener(
                  focusNode: FocusNode(),
                  onKey: (event) {
                    //print(event.data.logicalKey.keyId);
                     /* if (event.runtimeType == RawKeyDownEvent &&
                          (event.logicalKey.keyId == 54)) {Navigator.pop(context, this._textController.text);} */
                    
                  },
                  child: TextFormField(
                    controller: _textController,
                    onFieldSubmitted: (_textController) {
                      Navigator.pop(context, this._textController.text);
                    },
                    ),
                  ),

Good Luck,
dewball345

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.