android-studio - 无法在 Android Studio 中的现有颤振项目中打开不可为空的功能
问题描述
我在 Android Studio 4.0 的 Flutter 中有一个现有项目。我正在尝试将其迁移到默认情况下打开不可为空功能的开发通道。我做了什么:
- 更新了 pubspec.yaml 中的 SDK 要求:
environment:
sdk: ">=2.9.0-14.0.dev <3.0.0"
- 运行 pub get 和 pub upgrade:
> 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
具有以下内容的文件:
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.
但结果什么都没有。当我从 IDE 运行项目时,出现以下错误:
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;
^
我没有找到有关此案的任何明确的官方说明。
我做错了什么?
解决方案
自从在 Flutter 2 上稳定发布以来,Null-safety 一直是 Flutter 的一个特性。将环境配置更新为sdk: ">=2.12.0 <3.0.0"
、运行flutter clean
和flutter pub get
刷新项目,并具有 null-safety 支持。
推荐阅读
- java - Cassandra有线协议中“持续时间”的ProtocolID?
- ceph - Ceph 恢复软件无法在最新版本上运行
- django - Django Select2Widget 没有用脆的形式正确地设置样式
- excel - 在第一行的值第一次匹配后删除所有行
- matlab - 以矩阵形式从matlab中的多级对象获取属性
- javascript - 禁用“离开站点?” 使用 ContentTools 时的问题
- python - 在 __init__ 中设置 self.var 时出现 Python 错误
- postgresql - PostgreSQL 中的快速随机行:为什么 time (floor(random()*N)) + (select * from a where id = const) 比 select where id = random 少 100 倍?
- c# - Unity Build Doast 的工作方式与编辑器相同
- spring - 使用 JPA 存储库,jpql,本机查询查询