avoid_returning_widgets
Severity | Quick Fix | Options |
---|---|---|
Info | ❌ | ✅ |
Details
Avoid returning widgets from methods.
Static, overridden and extension methods are ignored.
Watch the video below to learn more about the advantages of using widgets as classes instead of methods.
Bad
class A extends StatelessWidget {
const A({super.key});
@override
Widget build(BuildContext context) {
return Column(
children: [
_buildWidget(),
_buildWidget(),
],
);
}
Widget _buildWidget() {
return ...;
}
}
Good
class A extends StatelessWidget {
const A({super.key});
@override
Widget build(BuildContext context) {
return const Column(
children: [
B(),
B(),
],
);
}
}
class B extends StatelessWidget {
const B({super.key});
@override
Widget build(BuildContext context) {
return ...;
}
}