Skip to main content

avoid-unnecessary-stateful-widgets

added in: 1.4.0
Pro+
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();
}
}