Skip to content

Document why TextEditingValue constructor with no parameters creates an invalid selection. #95978

@marcglasberg

Description

@marcglasberg

Any reason why the constructor with no parameters creates an invalid selection, with offset: -1?

  const TextEditingValue({
    this.text = '',
    this.selection = const TextSelection.collapsed(offset: -1),
    this.composing = TextRange.empty,
  }) : assert(text != null),
       assert(selection != null),
       assert(composing != null);

This should be the same as clearing it:

void clear() {
    value = const TextEditingValue(selection: TextSelection.collapsed(offset: 0));
  }

So that these are equivalent:

controller.clear();
controller.value = const TextEditingValue();

If there is a valid reason for the constructor with no parameters to create an invalid object, this should be clearly stated in the docs.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsd: api docsIssues with https://api.flutter.dev/frameworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions