avoid-unnecessary-stateful-widgets
preset: recommended
Warns when a StatefulWidget
can be converted to a StatelessWidget
.
Using a StatelessWidget
where appropriate leads to more compact, concise, and readable
code and is more idiomatic.
Example
❌ Bad:
// LINT
class MyWidget extends StatefulWidget {
const MyWidget({super.key});
State<MyWidget> createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
Widget build(BuildContext context) {
return Container();
}
}
✅ Good:
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
Widget build(BuildContext context) {
return Container();
}
}