Trying out the flutter_lints package

I made another post last month about using linting in Flutter projects but the other day I found out about a (relatively) new package called flutter_lints so I thought I'd try it out and give my impressions.

The (somewhat) older options

If you read my other post or use linting in your Flutter projects you'll probably already know that there were two major options up until now for linting:

I've used both and they are both pretty good, I use lints a lot more often though. I kind of get the feeling that lints is a little stricter but that just might be my imagination.

The new challenger(flutter_lints)

So I was browsing Twitter the other day and I saw a tweet in my timeline about flutter_lints. It looks like this package is actually endorsed and maintained by the Flutter Team. According to the pub.dev page it's built on top of the lints package I mentioned above:

This package is built on top of Dart's recommended.yaml set of lints from package:lints.

I also saw something else cool in the README:

Flutter apps, packages, and plugins created with flutter create starting with Flutter version 2.xx are already set up to use the lints defined in this package. Entities created before that version can use these lints by following these instructions:

It looks like this is going to come bundled automatically when you set up a new project from now on? I created a new Flutter project with 2.2.2 two days or so ago and couldn't confirm this but, so maybe it's something that hasn't landed on stable yet.

My impressions

So I decided to add flutter_lints to one of my older projects and take it for a test drive. If you need steps on how to do this you can check out my post from last month.

Unsurprisingly I found it to be really similar to lints, but I did notice I got a lot of 'Use widget key in constructors' warnings in my custom widgets. This warning is definitely fair, I just hadn't seen it before with lints or pedantic. Apart from that I mostly got the same warnings as with the other options, especially about adding const keywords 😅.

If this ends up automatically being added to all new projects it will be great, it'll take another step off my setup process. Plus, I never used to use any linting in my Flutter projects until a couple of months ago and I kind of regret not doing it sooner - it will definitely make things a lot cleaner and streamlined for newcomers.

21