TextEditingController constructor

TextEditingController({
  1. String? text,
})

Creates a controller for an editable text field, with no initial selection.

This constructor treats a null text argument as if it were the empty string.

The initial selection is TextSelection.collapsed(offset: -1). This indicates that there is no selection at all (TextSelection.isValid is false in this case). When a text field is built with a controller whose selection is not valid, the text field will update the selection when it is focused (the selection will be an empty selection positioned at the end of the text).

Consider using TextEditingController.fromValue to initialize both the text and the selection.

This example creates a TextField with a TextEditingController whose initial selection is empty (collapsed) and positioned at the beginning of the text (offset is 0).
link

To create a local project with this code sample, run:
flutter create --sample=widgets.TextEditingController.TextEditingController.1 mysample

Implementation

TextEditingController({ String? text })
  : super(text == null ? TextEditingValue.empty : TextEditingValue(text: text));