linter
linter copied to clipboard
sort_child_properties_last lint rule undermines its own intent for builder widgets
The linter that says "Sort child properties last in widget instance creations" is intended to make it so the widget construction cascade is properties-then-children so the heavily indented part comes after the relevant properties, like
SomeWidget(
scale: whatever,
favoriteFood: whatever,
child: SomeOtherWidget(
...
),
)
However, when the widget is a builder widget, the child-last constraint undermines this intent, because it ends up like
SomeBuilder(
scale: whatever,
favoriteFood: whatever,
builder: (_, child) {
return SomeOtherWidget(
...
);
},
child: child,
)
i.e. In the case of builder widgets the builder function is often the real child, in terms of where the cascade lives.
when the child of the builder is a complex widget tree rather than just child I do like having it after the builder particularly when the builder is fairly short as is better to avoid excessive widget rebuilds. On the other hand, the original intent of this lint is to make sure widget properties go after other properties. A builder is a widget property as the return type is a widget.
WDYT @goderbauer ?
I am with @jacob314 here: It depends. Sometimes its nice to have the child last, sometimes its better to put the builder last.
Should the rule then be something like:
- if no
builderargument:- a present
childorchildrenargument must be last.
- a present
- if a
builderargument is present:- a present
childorchildrenargument must be either: last or... just before thebuilderargument?
- a present
Or maybe:
- if a
builderargument is present:- and it is the last argument, then a present
childorchildrenargument must be second-to-last, - and it not the last argument, then a present
childorchildrenargument must be last.
- and it is the last argument, then a present