The Flutter Fix feature, introduced in Flutter 2, combines a Dart command-line tool with changes suggested by the Dart analyzer to automatically clean up deprecated APIs in your codebase.
This feature has also been added to IDE plugins for Flutter (2.0) and Dart (2.12). Depending on the IDE, these automated updates are called quick-fixes (IntelliJ, Android Studio, Eclipse) or code actions (VS Code).
Applying individual fixes
You can use any supported IDE to apply a single fix at a time.
IntelliJ and Android Studio
When the analyzer detects a deprecated API, a light bulb appears on that line of code. Clicking the light bulb displays the suggested fix that updates that code to the new API. Clicking the suggested fix performs the update.
A sample quick-fix in IntelliJ
When the analyzer detects a deprecated API, it presents an error. You can do any of the following:
- Hover over the error and then click the Quick Fix link. This presents a filtered list showing only fixes.
- Put the caret in the code with the error and click the light bulb icon that appears. This shows a list of all actions, including refactors.
- Put the caret in the code with the error and press the shortcut (Command+. on Mac, Control+. elsewhere) This shows a list of all actions, including refactors.
A sample code action in VS Code
Applying project-wide fixes
To see or apply changes to an entire project,
you can use the command-line tool,
This tool has two options:
To see a full list of available changes, run the following command:
dart fix --dry-run
To apply all changes in bulk, run the following command:
dart fix --apply
For more information on Flutter deprecations, see Deprecation lifetime in Flutter, a free article on Flutter’s Medium publication.