A tool to migrate API usage to Dart 2.
dart2_fix is a command line utility that can automatically migrate some Dart 1 API usages in your
source code to Dart 2 ones. Currently, it focuses on updating deprecated constant names; for example:
For more information about preparing your code for Dart 2, please see the Dart 2 migration guide.
To install, run
pub global activate dart2_fix. Then, from your project directory, run:
pub global run dart2_fix
When run without any arguments, it will check your project, but will not make changes; it'll indicate what would be changed if asked to make modifications. For example:
test/test/runner/load_suite_test.dart line 56 • Duration.ZERO => Duration.zero line 60 • Duration.ZERO => Duration.zero line 86 • Duration.ZERO => Duration.zero test/tool/host.dart line 169 • JSON => json line 173 • JSON => json Found 5 fixes in 2.3s. To apply these fixes, run again using the --apply argument.
To actually modify your project source code, run with the
--apply argument (
pub global run dart2_fix --apply):
Updating test... test/test/runner/load_suite_test.dart 3 fixes applied for Duration.ZERO => Duration.zero test/tool/host.dart 2 fixes applied for JSON => json Applied 5 fixes in 1.9s.
To run this tool on Flutter code, use:
flutter packages pub global activate dart2_fix
then - to check your code - run:
flutter packages pub global run dart2_fix
and to apply fixes, run:
flutter packages pub global run dart2_fix --apply
No. Currently this only fixes the renaming of various deprecated constant
names. Some of the less uniform constant renamings are not handled by this
tool. For example
Endianness.BIG_ENDIAN has been renamed to
this will not be caught. After running this tool, remaining issues can be found
by running the dart analyzer (or flutter analyze) and fixing any deprecation
This tool can't catch conflicts between the new constant names and any fields or
local variables that you might have in scope. If you get new analysis warnings
or runtime failures after running this tool, check to see whether one of the
changes made has caused a naming conflict with something else in scope. The
most common cause of this is having a local variable named
json in a scope
JSON.decode gets renamed to
json.decode. To help with fixing these
kinds of conflicts, the following top level members have been added to
base64UrlEncode. These top level members are equivalent to
json.decode, etc, and can be used to avoid naming conflicts where required.
Please file feature requests and bugs at the issue tracker.
Add this to your package's pubspec.yaml file:
dependencies: dart2_fix: "^1.0.1"
You can install packages from the command line:
$ pub get
$ flutter packages get
Alternatively, your editor might support
pub get or
Check the docs for your editor to learn more.
|1.0.1||Apr 3, 2018|
|1.0.0+2||Mar 29, 2018|
|1.0.0+1||Mar 28, 2018|
|1.0.0||Mar 28, 2018|
We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Detected platforms: Flutter, web, other
No platform restriction found in libraries.
The description is too short.
Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.
Maintain an example.
Create a short demo in the
example/directory to show how to use this package. Common file name patterns include:
example.dartor you could also use
Fix analysis and formatting issues.
Analysis or formatting checks reported 2 hints.
Strong-mode analysis of
lib/src/deprecation_analysis_server.dartgave the following hint:
line: 34 col: 10
The value of the local variable 'hadServerError' isn't used.
Strong-mode analysis of
lib/src/deprecation_analyzer.dartgave the following hint:
line: 35 col: 17
'locateContexts' is deprecated and shouldn't be used.
|Dart SDK||>=2.0.0-dev.36.0 <2.0.0|