Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 968
Philip Dolenko Avatar asked May 19 '20 10:05

Philip Dolenko


1 Answers

TextField set enableInteractiveSelection property to false can resolve this issue

like image 57
menttofly Avatar answered Oct 05 '22 14:10

menttofly