skip to Main Content

I’m working on a Flutter project, which will run on an android device that already has a physical keyboard built in.
Does anyone know how to never display the on screen keyboard, and only accept data from the physical keyboard?

I’ve tried using TextInputType.none (do not enter any characters), among other methods that whenever I type something the keyboard is displayed again.
I need the on screen keyboard to never be displayed and the characters typed on the physical keyboard to be entered.

2

Answers


  1. Chosen as BEST ANSWER

    Thanks the first option worked.

    And I added the TextEditingController inside a RawKeyboardListener, so every time there is a typing on the physical keyboard, the character will be added to the TextFormField.

         Padding(
            padding: ConstantsComponents.inputPadding,
            child: RawKeyboardListener(
                onKey: (key) => Utils.keyboardOnKey(controller, key) ,
                focusNode: FocusNode(
                    canRequestFocus: false,
                    descendantsAreFocusable: true
                ),
                child: TextFormField(
                    enableSuggestions: false,
                    autocorrect: false,
                    controller: controller,
                    readOnly: true
                )
            )
        );
    

  2. There are two ways you can do this:

    1. First:
      If you are using TextFormField widget:
    TextFormField(
    //You have to add the read-only property to true
        readOnly: true,
    ),
    
    1. If you want to hide keyboard when using custom TextInput, then you could use the SystemChannels class.
    import 'package:flutter/services.dart';
    
    SystemChannels.textInput.invokeMethod("TextInput.hide");
    

    For details, see this flutter issue: https://github.com/flutter/flutter/issues/16863

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search