I need to disable TextFormField occasionally. I couldn't find a flag in the widget, or the controller to simply make it read only or disable. What is the best way to do it?
相关问题
- What means in Dart static type and why it differs
- Flutter : Prepare list data from http request
- How to schedule an alarm on specific time in Flutt
- MappedListIterable is not a SubType
- 'firebase_messaging/FirebaseMessagingPlugin.h&
相关文章
- Observatory server failed to start - Fails to crea
- Flutter error retrieving device properties for ro.
- Adding Shadows at the bottom of a container in flu
- Flutter. Check if a file exists before loading it
- Flutter - http.get fails on macos build target: Co
- Receive share file intents with Flutter
- Do stateless widgets dispose on their own?
- How to clean your build with Flutter RP2 in Androi
This isn't a feature that is currently provided by the framework, but you can use a
FocusScope
to prevent aTextFormField
from requesting focus.Here's what it looks like when it's disabled.
(with hint text)
(with a readonly value)
Here's what it looks like when it's enabled.
(with focus)
(without focus)
Code for this is below:
This is another way of somehow disabling a
TextField
but keeping it's functionality. I mean foronTap
usageenableInteractiveSelection
will disable content selection of
TextField
FocusScope.of(context).requestFocus(new FocusNode());
change the focus to an unused focus node
Using this way, you can still touch
TextField
but can't type in it or select it's content. Believe me it's going to be useful sometimes ( datepicker, timepicker, ... ) :)