0

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
)
Cenk YAGMUR
  • 3,154
  • 2
  • 26
  • 42
  • In the context of a mobile app, this is a bit of a catch-22. The appearance of a blinking cursor means the text field is accepting input, but if the keyboard doesn't appear then there is no way to provide input. That situation strikes me as a very easy source of UI confusion on the part of the user. A better way to indicate that a text field is editable would be a descriptive hint text. – Abion47 Feb 24 '20 at 22:19
  • I want it just like whatsapp. There is a cursor on the whatsapp page, but the keyboard is closed – Cenk YAGMUR Feb 24 '20 at 23:52
  • With the knowledge that I still think this is bad UX design, I would suggest putting a timer for a second and a half or so that toggles the hint text of the `TextField` to be either a pipe character "|" or empty. – Abion47 Feb 25 '20 at 00:28

1 Answers1

3

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

Alex Myznikov
  • 919
  • 9
  • 19