Search code examples
flutterdartkeyboardfocus

Make keyboard show up without TextField


Is there a command in Flutter to make the onscreen keyboard on mobile devices appear? I am aware of using FocusNodes to get the keyboard to show for TextFields but I have a situation that does not use any TextFields and I would still like to be able to open and dismiss the onscreen keyboard.

Thanks!

Edit: Here's the piece of code I'm using. It's being called on the onPointerDown callback of a Listener widget

void handleTap(PointerDownEvent pointerDownEvent) {
    // Get input focus
    _keyboardFocusNode.requestFocus(); // Works fine

    print("In callback"); // Prints fine

    // Bring up keyboard 
    SystemChannels.textInput.invokeMethod('TextInput.show'); // Nothing happens
...
}

I'm testing this on the iOS simulator. I have hardware keyboard unchecked (to use the software keyboard instead).


Solution

  • to show Keyboard use:

    SystemChannels.textInput.invokeMethod("TextInput.show");
    

    And to hide it:

    SystemChannels.textInput.invokeMethod("TextInput.hide");