androidflutterkotlinmobilemobile-application

How can I focus on an input in Android without the keyboard appearing?


I have a device running the Android operating system, and at the bottom of my device, there is a QR scanner. The device will be installed in a restaurant's kitchen. Its purpose is to display orders placed by the waiters and print a receipt when the order is started. Once the receipt is printed, I need to capture the QR data when the QR code on the receipt is scanned. I created an input for this and set its opacity to 0. As soon as the page opens, I set focus on the input, but when I do this, the system keyboard appears, causing an unpleasant display. How can I prevent this keyboard from appearing?

I am developing my application with Flutter SDK, but I can also use kotlin code to solve my problem.

i first tried focusing on the input and then closing the keyboard, but when I wrote the code to close the keyboard, it closed the keyboard but also lost focus, so I can't retrieve the QR value.


Solution

  • If you use flutter and use TextFormField or TextField widget, there is a property called keyboardType to set your keyboard type. For setting prevent the keyboard show when the field is on focus set keyboardType: TextInputType.none.

    Code example

    TextFormField(
      controller: _yourController,
      // [keyboardType] properties for setting keyboard appearance,
      // set it to [TextInputType.none] will hide the keyboard.
      keyboardType: TextInputType.none,
    ),