Cenk YAGMUR
Cenk YAGMUR

Reputation: 3451

How can i do flutter autofocus but keyboard dismiss

Whenever the page opens, I want the cursor to appear, but I don't want a keyboard. Does anyone know how I can do it?

TextField(
  textCapitalization:TextCapitalization.sentences,
  controller: _textEditingController,
  autofocus: true
)

Upvotes: 0

Views: 3071

Answers (1)

Alex Myznikov
Alex Myznikov

Reputation: 969

You can use SystemChannels to get access to the channel that exposes a system text input control. Call TextInput.hide method on it to hide a keyboard once the TextField is built.

A straightforward example of doing this is:

Widget build(BuildContext context) {
  Future.delayed(const Duration(), () => SystemChannels.textInput.invokeMethod('TextInput.hide'));

  return Scaffold(
    body: TextField(
      autofocus: true,
    ),
  );
}

This may help if you don't like an idea of using Future here: Flutter: Run method on Widget build complete

Upvotes: 3

Related Questions