avoid-empty-setstate

Path
lint/correctness/avoid-empty-setstate
Default
On (recommended)
Origin
Falcon
Domain
flutter
Rule
60 of 512
recommendedflutter

Avoid setState callbacks with empty block bodies. Comments and empty statements do not update state; unrelated methods are ignored.

Invalid

example.dartdart
import 'package:flutter/material.dart';
class S extends State<StatefulWidget> { void update() {
setState(() { ; });
setState(() { /* comment */ });
this.setState(() {});
setState((() {}));
setState(() { ; ; });
}}
Avoid an empty `setState` callback; update state inside the callback.
2class S extends State<StatefulWidget> { void update() {
3setState(() { ; });
Avoid an empty `setState` callback; update state inside the callback.
3setState(() { ; });
4setState(() { /* comment */ });
Avoid an empty `setState` callback; update state inside the callback.
4setState(() { /* comment */ });
5this.setState(() {});
Avoid an empty `setState` callback; update state inside the callback.
5this.setState(() {});
6setState((() {}));
Avoid an empty `setState` callback; update state inside the callback.
6setState((() {}));
7setState(() { ; ; });

Valid

example.dartdart
import 'package:flutter/material.dart';
class S extends State<StatefulWidget> { int x = 0; void update() {
setState(() { x++; });
setState(() => x++);
this.setState(() { x = 2; });
setState(() { update(); });
setState(() { if (x == 0) x = 1; });
}}

Configure avoid-empty-setstate

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

falcon.jsonjson
{
  "linter": {
    "rules": {
      "correctness": {
        "avoid-empty-setstate": "error"
      }
    }
  }
}

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

example.dartdart
// falcon-ignore lint/correctness/avoid-empty-setstate: <reason>