How to update old Flutter projects with Dart Fix --apply

Have you ever tried to update an old Flutter project to the latest APIs and lint rules and got a ton of warnings like in this example?

Flutter analyze warnings after updating an old project to the latest lint rules
Flutter analyze warnings after updating an old project to the latest lint rules

This is very common, especially when you update Flutter to a new version on your system.

For example, all the text styles have been renamed in Flutter 3.7 as part of the migration to Material 3:

All text styles have been renamed as part of the migration to Material 3
All text styles have been renamed as part of the migration to Material 3

Rather than fixing all these warnings by hand, you can just run a simple command and watch the magic happen:

dart fix --apply

This will fix most of the warnings for you.

But in some cases, dart fix can't determine the correct fix with certainty, so you'll have to do this by hand. This is easy and mostly a case of using the quick fix shortcut in VSCode (CMD+. on MacOS, CTRL+. on Windows).

Use the Quick Fix option to fix warnings that are not resolved by Dart fix
Use the Quick Fix option to fix warnings that are not resolved by Dart fix

To better understand how dart fix works and how to use it alongside the Flutter analyzer, watch this video:

Bonus: Fix all on Save

One cool thing about VSCode is that we can use the command palette to fix all issues on the current file:

Using the Fix All option from the command palette
Using the Fix All option from the command palette

But you know what's even better?

Fix All on Save. 🚀

Just add "source.fixAll" to "editor.codeActionsOnSave" on your VSCode settings, and you're good to go!

You can grab my VSCode settings.json file from here. For all my other time-saving tips, read: VSCode Shortcuts, Extensions & Settings for Flutter Development

When it comes to addressing linter issues, Dart and VSCode offer great tooling that can save you a lot of time. 🚀

So make sure you make the most of it. 👍

Happy coding!

Want More?

Invest in yourself with my high-quality Flutter courses.

Flutter Foundations Course

Flutter Foundations Course

Learn about State Management, App Architecture, Navigation, Testing, and much more by building a Flutter eCommerce app on iOS, Android, and web.

Flutter & Firebase Masterclass

Flutter & Firebase Masterclass

Learn about Firebase Auth, Cloud Firestore, Cloud Functions, Stripe payments, and much more by building a full-stack eCommerce app with Flutter & Firebase.

The Complete Dart Developer Guide

The Complete Dart Developer Guide

Learn Dart Programming in depth. Includes: basic to advanced topics, exercises, and projects. Fully updated to Dart 2.15.

Flutter Animations Masterclass

Flutter Animations Masterclass

Master Flutter animations and build a completely custom habit tracking application.