I want to upgrade a project to null safety.
I use flutter SDK 3.13.5.
Dart SDK version: 3.1.2 (stable) (Tue Sep 12 16:26:23 2023 +0000) on "windows_x64"
When I execute the command
> dart pub upgrade --mode=null-safety
I got this error:
Could not find an option named "mode".
Usage: dart pub upgrade [dependencies...]
-h, --help Print this usage information.
--[no-]offline Use cached packages instead of accessing the network.
-n, --dry-run Report what dependencies would change but don't change any.
--[no-]precompile Precompile executables in immediate dependencies.
--major-versions Upgrades packages to their latest resolvable versions, and updates pubspec.yaml.
-C, --directory=<dir> Run this in the directory <dir>.
The documentation is not up to date https://dart.dev/tools/pub/cmd/pub-upgrade (null-safety available…)
Also tried
> dart pub upgrade --null-safety
but indicate ‘is no longer supported’.
How to do? (without this option, it upgrade to the latest version)
Thank you!
2
Answers
SOLVED I saw in the console that i need dart 2.19. So I went to https://docs.flutter.dev/release/archive?tab=windows and took flutter sdk 3.7.12 that have le latest dart 2.19.x. Command are now available. Hop it helps.
you are using an older version of
Flutter (3.13.5)
, and the--mode=null-safety
option is not available in that version. The--mode=null-safety
option is used in earlier versions of the Dart SDK before the official null safety support was introduced.run those commands, and i hope it will help you to resolve your issue:
dart pub outdated --mode=null-safety
If any of your dependencies are not null-safe, you will need to update them to null-safe versions.
Once all of your dependencies are null-safe, run:
dart pub upgrade
This will upgrade all of your dependencies to their latest versions, and it will also enable null safety in your project.