dart-lang / linter

Linter for Dart.
https://dart.dev/tools/linter-rules
BSD 3-Clause "New" or "Revised" License
636 stars 170 forks source link

IncorrectParentWidget #5096

Open bailerG opened 1 month ago

bailerG commented 1 month ago

A lint to avoid cases where a Flexible widget is placed outside a Row or Column and furthermore avoid blank screens on production would be very helpful and useful.

bwilkerson commented 1 month ago

@goderbauer

IIRC we've discussed a similar proposal in the past.

bwilkerson commented 1 month ago

I don't think we want to implement a lint like this using a hardcoded list of valid (parent, child) pairs. It's too easy for such a list to get out of sync with the widget library as the library evolves.

I suspect that instead we'd want to create an annotation that can be used by a widget author to specify any constraints on where the widget can be placed. Not only would that allow widget authors to update the constraints as the implementation changes, it would also allow widgets outside flutter to express the same constraints.