Skip to content

text_field_without_value_channel

Reports a text field with no way to read what is typed into it. Give it a controller, an onChanged or another way to read the text.

Tier
advisory
Scope
Flutter
Lowest preset
recommended
Fix
none

A TextField, TextFormField, CupertinoTextField or CupertinoTextFormFieldRow with no way to read what is typed into it. The violation covers the constructor’s name.

A field has a way to read it when it has:

  • an argument named controller, onChanged, onSubmitted, onFieldSubmitted, onSaved, validator or onTap, other than the literal null;
  • a key that is a GlobalKey;
  • an argument you list in value_arguments.

A field that takes no text is not reported either: readOnly other than the literal false, or enabled other than the literal true.

The rule is silent in a package that does not use Flutter.

What the user types is lost: nothing holds the text and nothing is told of it.

Violating
TextField(decoration: InputDecoration(labelText: 'Name'))
Corrected
TextField(
controller: _name,
decoration: InputDecoration(labelText: 'Name'),
)

Set under the assay: key of the project’s root analysis_options.yaml.

Rule parameter Default Effect
enabled true false switches the rule off for the whole project.
exclude [] Path globs where the rule is silent.
value_arguments [] More argument names through which the typed text is read.

Write why on the line directly above the suppression:

// Why this place is fine.
// ignore: assay/text_field_without_value_channel

// ignore_for_file: assay/text_field_without_value_channel silences it in a whole file, and // ignore: text_field_without_value_channel without the prefix works too. See Suppressions.