The EditableText widget is predefined in the Flutter framework and is used to create a text field that enables users to edit and input text. It is a fundamental widget for constructing text input fields in Flutter applications. This widget can be customized and provides the ability to control text editing, including functions such as keyboard input, text selection, and cursor placement.
Here are some key features of the EditableText
widget:
- Text editing: Allows users to input, edit, and delete text.
- Customizable: Can be customized with various properties, such as text style, font size, color, and more.
- Controller: This can be controlled using a
TextEditingController
to manage the text value and selection. - Focus: Can receive focus and respond to keyboard events.
- BackgroundCursorColor: Color of the background cursor.
- TextInputAction: Defines the action button on the keyboard (e.g., done, next).
Comparison WIth TextFeild
TextField
- Higher-level widget
- Easier to use
- Built-in features and styling
- Supports input decoration
EditableText:
- Lower-level widget
- requires more setup
- provides fine-grained control
- Customizable text input behavior
Example
EditableText(
controller: _controller,
focusNode: _focusNode, //The FocusNode provides listeners that can alert you when the focus update.
style: TextStyle(fontSize: 20, color: Colors.black),
cursorColor: Colors.blue,
backgroundCursorColor: Colors.grey,
keyboardType: TextInputType.text,
textInputAction: TextInputAction.done,
);