简体   繁体   中英

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
)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM