Skip to main content

avoid-empty-setstate

added in: 1.3.0

Warns when a setState callback is empty.

Example

❌ Bad:

class _FooState extends State<StatefulWidget> {
Widget build(context) {
return FooWidget(
onChange: (value) async {
setState(() {}); // LINT
},
);
}
}

✅ Good:

class _FooState extends State<StatefulWidget> {
String _myState;

Widget build(context) {
return FooWidget(
onChange: (value) async {
setState(() {
_myState = 'changed';
});
},
);
}
}