Flutter: How to hide TextField text pointer (cursor) when use initial value text (Android)

Viewed 7657

Use case: Messaging app you edit your message: keyboard, blinking cursor and initial text appears but pointer (cursor) is not

But on Flutter when you use initial text (or via textController) there are always pointer(cursor) which is not wanted

Example

enter image description here enter image description here

Steps to reproduce: run flutter create bug

edit main.dart to replace center text (line 100) to MyStatefulPage(),

class MyStatefulPage extends StatefulWidget {
  @override
  State<MyStatefulPage> createState() {
    return _MyStatefulPageState();
  }
}
class _MyStatefulPageState extends State<MyStatefulPage> {

  TextEditingController controller;

  @override
  void initState() {
    super.initState();
    controller = new TextEditingController();
    controller.text = 'My Initial Text';
  } 

  @override
  Widget build(BuildContext context) {
    return TextField(
      decoration: InputDecoration(
       border: InputBorder.none
      ),
      // showCursor: false,
      controller: controller,
      autofocus: true,
      maxLines: 8,
    );
  }
}

With that code when you open app keyboard will appear but so will pointer(cursor) I want to hide this cursor(pointer).

Note: it's only for Android.

2 Answers

TextField set enableInteractiveSelection property to false can resolve this issue

TextFormField cursorHeight: 0 and cursorWidth: 0 can hide the cursor.

Related