Scorb
Scorb

Reputation: 1940

How do I run 'flutter pub get' while using unsound null safety?

The flutter docs specify here that unsound null safety allows for you to build with dependencies that are not using null safety.

The problem is that I cannot even run 'flutter pub get' with a package that does not have null safety.

When I run 'flutter pub get' I get the following error...

The current Dart SDK version is 3.1.2.

Because myapp depends on old_dependency from path which doesn't support null safety, version solving failed.

The lower bound of "sdk: '>=2.6.0 <3.0.0'" must be 2.12.0 or higher to enable null safety.
For details, see https://dart.dev/null-safety

It is not clear to mean in the above linked article exactly how I am supposed to run with non null safety dependencies.

The article says I can use "flutter run --no-sound-null-safety" but this same flag does not work for "flutter pub get --no-sound-null-safety".

Upvotes: 0

Views: 205

Answers (2)

Codefarmer
Codefarmer

Reputation: 1535

From your error message, you are having a flutter version using dart 3 and above. However, your projects runs on a flutter version pre dart 3(2.6.0 <= x < 3.0.0). You cant run unsound null safety in dart 3, as dart 3 runs with full null safety and the flag --no-sound-null-safety has been removed. You have the below options:

  1. Use a flutter version that supports unsound null safety. Typically, flutter versions up to flutter 3.7.x. Depending on the version you are using, you will have to work on deprecated issues also.
  2. You could opt to migrate your project to full null safety.

Upvotes: 2

Randal Schwartz
Randal Schwartz

Reputation: 44220

You need to follow the migration instructions to bring up your legacy application to at least null safety before you can start using Flutter 3.10 which has Dart 3.

Using Flutter 3.7, you can perform the instructions at https://dart.dev/null-safety/migration-guide, and then you can switch back to stable Flutter.

I recommend that you use Puro to have both the legacy and new flutter installations simultaneously without conflict, as shown in my video.

Upvotes: 0

Related Questions