How to Disable TextField In Flutter?
TextField Widget in Flutter Application is used to get data from users and store that data into the database. So in this article, we will be going through How to Disable TextField In Flutter.
How to Disable TextField In Flutter?
- TextField now has enabled property. where you can just disable the TextField like
new TextField( enabled: false, ... ... )
TextField and TextFormField both have an argument called enabled. You can control it using a boolean variable. enabled=true means it will act as an editing text field whereas enabled=false will Disable the TextField Widget.
- Create AlwaysDisabledFocusNode and pass it to the focusNode property of a TextField Widget.
class AlwaysDisabledFocusNode extends FocusNode { @override bool get hasFocus => false; }
then you can also use this, as shown below:
new TextField( enableInteractiveSelection: false, // will disable paste operation focusNode: new AlwaysDisabledFocusNode(), ... ... )
User can also try like a below:
TextField( enableInteractiveSelection: false, focusNode: FocusNode(), )
enableInteractiveSelection will disable content selection of TextField .
Similar to disabled in HTML
TextField( enable: false )
So you can also make it happen like below:
AbsorbPointer( absorbing: true, //To disable from touch use false while **true** for otherwise child: Your WidgetsName );
I have used a combination of readOnly and enableInteractiveSelection properties to achieve the desired behavior on the TextField Widget.
TextField( readOnly: true, enableInteractiveSelection: true, onTap: () { do_something(), }, )
Next up we will learn flutter textfield disable keyboard, flutter disable button, textfield flutter, flutter textfield not working, flutter textfield overflow, flutter textfield set value, flutter textfield default text, textfield flutter documentation, etc.
So Stay tuned:)
Conclusion:
So that’s it for today, Hope you have enhanced your knowledge of flutter.
Keep Learning !!! Keep Fluttering !!!
Still, need Support for Flutter Development? Do let us know.
FlutterAgency.com is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget Guide, Flutter Projects, Code libs and etc.
FlutterAgency.com is one of the most popular online portals dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge of Flutter.