Ash Khachatryan
Ash Khachatryan

Reputation: 455

Flutter TextField disable input

Can I disable input in TextField with open keyboard?

I am trying TextField with readOnly property, but when I set readOnly value true my device keyboard hide. I want do this without hidding keyboard

Upvotes: 4

Views: 8055

Answers (3)

Faris Ramadhan
Faris Ramadhan

Reputation: 31

As for now, you can do this by adding enabled to your TextField.

TextField(
 controller: _controller,
 enabled: false,
);

Upvotes: 3

Jigar Patel
Jigar Patel

Reputation: 5423

One way to do this is like so.

class _MyWidgetState extends State<MyWidget>{
  var tc = TextEditingController();
  var readOnlyText = 'read only';

  @override
  void initState() {
    super.initState();
    tc.text = readOnlyText;
  }

  @override
  Widget build(BuildContext context) {
    return TextField(
        controller: tc,
        onChanged: (_){
          tc.text = readOnlyText;
          tc.selection = TextSelection.fromPosition(TextPosition(offset: tc.text.length));
        },
    );
  }
}

Upvotes: 0

dm_tr
dm_tr

Reputation: 4763

You can try this

TextField(
   readyOnly: true,
   showCursor: true,
   // ...
),

Upvotes: 9

Related Questions