avoid-missing-controller

Path
lint/correctness/avoid-missing-controller
Default
Off, opt in
Origin
Falcon
Domain
flutter
Rule
85 of 512
flutter

Require Flutter text fields to expose their updated value.

TextField, TextFormField, CupertinoTextField, and EditableText need a non-null controller or a value callback supported by that API. Explicit readOnly:true and enabled:false fields are display-only and skipped. Dynamic expressions are accepted; unrelated classes and shadowed constructors are ignored.

Invalid

example.dartdart
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' as f;

void fields() {
  TextField();
  TextFormField();
  f.CupertinoTextField.borderless();
  new EditableText(controller: null);
  TextField(controller: null, onChanged: null);
  TextFormField(onSaved: null);
}
Provide a controller or a callback that receives the updated field value.
4void fields() {
5 TextField();
Provide a controller or a callback that receives the updated field value.
5 TextField();
6 TextFormField();
Provide a controller or a callback that receives the updated field value.
6 TextFormField();
7 f.CupertinoTextField.borderless();
Provide a controller or a callback that receives the updated field value.
7 f.CupertinoTextField.borderless();
8 new EditableText(controller: null);
Provide a controller or a callback that receives the updated field value.
8 new EditableText(controller: null);
9 TextField(controller: null, onChanged: null);
Provide a controller or a callback that receives the updated field value.
9 TextField(controller: null, onChanged: null);
10 TextFormField(onSaved: null);

Valid

example.dartdart
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' as f;

void fields(Object? controller, Function callback) {
  TextField(controller: controller);
  TextFormField(onChanged: callback);
  f.CupertinoTextField.borderless(onSubmitted: callback);
  EditableText(onChanged: callback);
  TextFormField(onSaved: callback);
  TextFormField(onFieldSubmitted: callback);
  TextField(controller: TextEditingController());
  TextField(readOnly: true);
  TextFormField(enabled: false);
  CupertinoTextField.borderless(readOnly: true);
  EditableText(readOnly: true);
}
void shadow(dynamic TextField) { TextField(); }

Configure avoid-missing-controller

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "correctness": {
        "avoid-missing-controller": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/correctness/avoid-missing-controller: <reason>