Open navaronbracke opened 1 year ago
Does this sound right, @goderbauer ?
Good question. In the example given the container is definitely unnecessary and should be removed, but I am not sure if that's true for all empty containers. They could be used to fulfill the responsibilities of a SizedBox.shrink()
or SizedBox.expand()
, in which case they are not really unnecessary (although they could be replaced with something more optimal).
I get the sense that the spirit of the avoid_unnecessary_containers
lint is to flag containers that can be removed without replacement. I don't think that is true for all instances of empty Container()
s. Some of these may have to be replaced with a SizedBox and I am not sure if we can detect automatically detect which category a container falls into (I couldn't even describe it verbally).
With that, I am not sure if flagging all empty containers is in the spirit of this lint?
That is indeed an open question I had too (hence the TBD)
I often see empty containers that don't have such a parent, though. I.e. as a child of a Column or inside a Padding, as the result of a ternary expression. (these are just two examples)
I often have to bring this up during code reviews, hence why I filed this (rather optimistic) issue.
Describe the issue The lint
avoid_unnecessary_containers
does not flag an empty container widget.To Reproduce
Expected behavior The lint
avoid_unnecessary_containers
should flag the empty container.TBD: if wrapping said container in a SizedBox / ConstrainedBox / DecoratedBox should be flagged, as all these force styling or min/max sizes, which can probably be avoided by rewriting code anyway, because the empty container does not add value while being the child.
Additional context