Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The Flutter TextEditingController does not clear the text in a TextFormField that is set to readOnly because readOnly means that the text field is not editable by the user, but it can still be modified programmatically.

In other words, setting a TextFormField to readOnly does not prevent the TextEditingController from modifying its text. Therefore, clearing the TextEditingController's text in a readOnly field would contradict this behavior.

If you want to clear the text in a readOnly field, you can use the TextEditingController to set its text to an empty string. However, you should also change the field's readOnly property to false before clearing the text, and revert it back to true afterward. This ensures consistency between the field's readOnly property and its current state.