avoid-stateless-widget-initialized-fields
added in: 1.5.0
warning
Warns when a StatelessWidget
has an initialized final field.
Non-static initialized fields are usually a sign of a state. Consider converting the widget to StatefulWidget
.
Example
❌ Bad:
class AnotherWidget extends StatelessWidget {
final initialized = <String>{}; // LINT
late final someField = <String>{}; // LINT
}
✅ Good:
class AnotherWidget extends StatelessWidget {
static final initialized = <String>{};
final someField;
const AnotherWidget(this.someField);
}
// Or
class _AnotherWidgetState extends State<AnotherWidget> {
final initialized = <String>{};
late final someField = <String>{};
}