'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
Solution 1:[1]
You can try this
TextField(
readyOnly: true,
showCursor: true,
// ...
),
Solution 2:[2]
As for now, you can do this by adding enabled to your TextField.
TextField(
controller: _controller,
enabled: false,
);
Solution 3:[3]
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));
},
);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | dm_tr |
| Solution 2 | Faris Ramadhan |
| Solution 3 | Jigar Patel |
