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
What it reports
Section titled “What it reports”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,validatororonTap, other than the literalnull; - a
keythat is aGlobalKey; - 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.
Example
Section titled “Example”TextField(decoration: InputDecoration(labelText: 'Name'))TextField( controller: _name, decoration: InputDecoration(labelText: 'Name'),)Rule parameters
Section titled “Rule parameters”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. |
Suppressing it
Section titled “Suppressing it”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.