0

I'm creating a "barcoder" text field on flutter. After the page opened which is the barcoder belong,

I need to autofocus on TextField. But on the first opening, I want to hide the keyboard. And then if the user focuses on TextField The keyboard can appear.

How can I achieve this? I already try

class FirstDisabledFocusNode extends FocusNode {
  @override
  bool consumeKeyboardToken() {
    return false;
  }
}

and it didn't work.

Here is my code

Card(
    elevation: 1,
    child: TextField(
      autofocus: true,
      focusNode: textFieldFocusNode,
      onEditingComplete: () {
        print('Barcode: ${textController.text}');
        buttonFocusNode.requestFocus();
        events!(context);
        if (textController.text.isNotEmpty) {
          _audioCache.play('success.mp3');
        }
      },
      controller: textController,
      decoration: const InputDecoration(
          fillColor: Colors.white,
          prefixIcon: Icon(Icons.qr_code),
          hintText: 'Barcode',
          focusColor: Palette.asBlue,
          border: InputBorder.none,
          focusedBorder: InputBorder.none),
    ),
  );
OguzKaanAkyalcin
  • 621
  • 2
  • 8
  • 25

1 Answers1

1

When it goes to the next screen, you can use this in the initState of that widget.

 void initState() {
 super.initState();
 Future.delayed(
   Duration(),
   () => SystemChannels.textInput.invokeMethod('TextInput.hide'),
  );
 }

if it didn't work click the link that i provided in the comments.

Hama Sabah
  • 342
  • 4
  • 9