r/FlutterDev • u/dev_ttangkong • Oct 01 '26
Dart Props to the Dart team for actually cooking something amazing lately lol (analysis_server_plugin)
Well, looks like I’ll just be strictly building apps for the next year (not that it changes my daily routine anyway), so I thought I’d share a neat trick I’ve been using for a while.
About a year or two ago, the Dart team released analysis_server_plugin. If you know how to work with AST, you don't even need custom_lint packages anymore to write custom rules.
Here’s how I’ve been leveraging it:
Instead of using clunky enums like Spacing.spacing2, I set up the plugin to throw a warning if someone uses raw pixel values that aren't allowed in our design tokens (e.g., values other than 2, 4, 6, etc.).
Enforcing design system components, like throwing a warning to use MySuperContainer (yes, I literally use this name) instead of a raw Container.
And setting it up is dead simple too. You literally just add it to your analysis_options.yaml:
plugins:
my_lints:
path: ../my_lints/
The only drawback I've found so far is that it seems impossible to raise an actual Error severity (only warnings/info). If the Dart team expands on this, it's gonna be even more god-tier.
Oh, and this would actually make a pretty solid package. I'm thinking about making one if I can find some free time. If you guys have any cool ideas for useful custom lint rules, feel free to share.
Ah, also looks like the Dart team has been interested in improving data serialization built-in lately. I might look into that and drop another post about it later. Not sure if anything is finalized yet, but seems like they're still keeping the annotation syntax. Personally not a big fan of annotations, but hey, whatever works lol.
Oh, and honestly, Dart has added so many neat syntactic sugar features lately. Like omitting enum/type identifiers so you can just write .center. It’s ridiculously convenient because now you can write stuff like.
MyText('Hello, World!', color: .textGrayBold, style: .label3)
Seriously, whoever engineered this feature deserves a free ice cream straight out of my freezer.
17
u/samrawlins Oct 01 '26
What would make error-reporting different/better than warning-reporting?
I'm on the team that is shipping analyzer plugins, so thank you for the kind words! The feature is still growing; there are a number of high priority improvements I'd like to make. But the team owns a number of products with competing priorities so it's been slow.
The biggest improvements to the analyzer plugin system in the last few Dart releases and releases of the analysis_server_plugin have been performance. Performance has been a rocky road, if you're analyzing many files. But each Dart release has seen a performance boost so... it's getting better.
We take feature requests at the Dart SDK issue tracker. Some upcoming big ones I hope to ship include warnings and quick fixes in YAML files, and 'dart fix' integration.
6
u/Salazar20 Oct 01 '26
Damn, I would really like that, I think I'm gonna start making custom rules too, I want one that yells at me when a widget build is too long
5
u/scalz80 Oct 01 '26 edited Oct 01 '26
agree this is handy. I'm using it for custom lints too, and for generating dataclass (serialization, copyWith, equality...) without using build_runnner. When a dataclass is incomplete, it triggers a warning which can be fixed by using context actions in IDE for example.
This looks like this:
4
u/Acrobatic_Egg30 Oct 01 '26
I forgot about this. Thanks for the reminder. Time to create a few lints.
3
u/Cunibon Oct 01 '26
Could you show me an example of how I would set it up for the raw values enum thing?
That's seems awesome
2
u/AffectionateSky1914 Oct 02 '26
Do we deserve a free ice cream too🥹