I have an existing project in Flutter in Android studio 4.0. I'm trying to migrate it to the dev channel with non-nullable feature turned on by default. What I did:
environment:
sdk: ">=2.9.0-14.0.dev <3.0.0"
> flutter --version
Flutter 1.20.0-3.0.pre • channel dev • https://github.com/flutter/flutter.git
Framework • revision 0af027f805 (30 hours ago) • 2020-07-04 12:19:20 -0700
Engine • revision a751393804
Tools • Dart 2.9.0 (build 2.9.0-20.0.dev 22da8934ac)
analysis_options.yaml
file with the following content:analyzer:
enable-experiment:
- non-nullable
> dart --enable-experiment=non-nullable
Usage: dart [<vm-flags>] <dart-script-file> [<script-arguments>]
Executes the Dart script <dart-script-file> with the given list of <script-arguments>.
Common VM flags:
--enable-asserts
Enable assert statements.
--help or -h
Display this message (add -v or --verbose for information about
all VM options).
--packages=<path>
Where to find a package spec file.
--observe[=<port>[/<bind-address>]]
The observe flag is a convenience flag used to run a program with a
set of options which are often useful for debugging under Observatory.
These options are currently:
--enable-vm-service[=<port>[/<bind-address>]]
--pause-isolates-on-exit
--pause-isolates-on-unhandled-exceptions
--warn-on-pause-with-no-debugger
This set is subject to change.
Please see these options (--help --verbose) for further documentation.
--write-service-info=<file_uri>
Outputs information necessary to connect to the VM service to the
specified file in JSON format. Useful for clients which are unable to
listen to stdout for the Observatory listening message.
--snapshot-kind=<snapshot_kind>
--snapshot=<file_name>
These snapshot options are used to generate a snapshot of the loaded
Dart script:
<snapshot-kind> controls the kind of snapshot, it could be
kernel(default) or app-jit
<file_name> specifies the file into which the snapshot is written
--version
Print the SDK version.
But the result is nothing. When I run the project from IDE I get the following error:
Launching lib\main.dart on AOSP on IA Emulator in debug mode...
Running Gradle task 'assembleDebug'...
lib/ui/test.dart:21:6: Error: This requires the 'non-nullable' language feature to be enabled.
Try updating your pubspec.yaml to set the minimum SDK constraint to 2.9 or higher, and running 'pub get'.
int? v = 0;
^
I didn't found any clear official instructions on this case.
What I'm doing wrong?
You can enable the experiment using the '--enable-experiment=non-nullable' command line option. To be able to utilize these new features, apps can either migrate to null-safe Dart or run in mixed mode.
Copy: --no-sound-null-safety and add into "additional run args". Run your app with "Run/Play" Button or from "Run" Menu. In this way, you can solve "Error: Cannot run with sound null safety, because the following dependencies don't support null safety" error on Flutter project.
Null-safety has been a feature of Flutter ever since its stable release on Flutter 2. Update the environment config to sdk: ">=2.12.0 <3.0.0"
, run flutter clean
and flutter pub get
to refresh the project and have null-safety support.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With