Can the Dart analyzer prevent compilation if I pass a particlar subclass as an argument to a method?

27 Views Asked by At

I am upgrading an older app from Flutter 2 to Flutter 3, and one problem I have encountered is that the TextButton.icon() goes crazy if child is a Flexible. This did not happen with FlatButton.icon(), which worked just fine.

So I'm wondering if there is a way to use the Dart analyzer to my advantage, to prevent the code from even compiling if I'm passing a Flexible() as a child to TextButton.icon() anywhere in the code?

I know that of course I can search and replace in the code, but I'm more interested to know if the Dart analyzer can be used to perform this kind of analysis somehow?

1

There are 1 best solutions below

0
Randal Schwartz On

You can use the custom_lint package to write custom lints to do whatever you want. It's a nice simplification (and documentation!) of the existing analyzer API, but apparently much easier to write it to do what you want. You can even write "quick fixes" if you desire.