prefer-single-setstate
Suggests merging multiple consecutive setState
invocations into a single invocation.
Example
❌ Bad:
class _SomeState extends State<StatefulWidget> {
void someMethod() {
// ...
setState(() {
// some logic
});
// LINT: Prefer calling 'setState' only once.
// Try moving all callback logic to the previous invocation.
setState(() {
// another
});
}
}
✅ Good:
class _SomeState extends State<StatefulWidget> {
void someMethod() {
setState(() {
// some logic
// another
});
}
}