flutter run 运行报错Error: Cannot run with sound null safety

flutter run 报错 Error: Cannot run with sound null safety, because the following dependencies don't support null safety

错误信息

Launching lib/main.dart on iPhone 12 Pro Max in debug mode...
Running Xcode build...
Xcode build done.                                           26.8s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **


Xcode's output:
↳
    Error: Cannot run with sound null safety, because the following dependencies
    don't support null safety:

     - package:url_launcher

    For solutions, see https://dart.dev/go/unsound-null-safety

    Command PhaseScriptExecution failed with a nonzero exit code
    note: Using new build system
    note: Building targets in parallel
    note: Planning build
    note: Analyzing workspace
    note: Constructing build description
    note: Build preparation complete
    /Users/jq_chan/AndroidStudioProjects/flutter_app/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.5.99. (in target 'Flutter' from project 'Pods')

Could not build the application for the simulator.
Error launching application on iPhone 12 Pro Max.

由上面错误信息可以知道,url_launcher这个包不支持空类型安全(null safety)。关于null safety,可以查看这篇文章——【译】Flutter 1.20 中悄然带来的 null safety

解决方法

  • VS Code
  1. .vscode/launch.json文件中添加args参数
"args": [
    "--no-sound-null-safety"
]

完整代码如下:

{
       // Use IntelliSense to learn about possible attributes.
       // Hover to view descriptions of existing attributes.
       // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
       "version": "0.2.0",
       "configurations": [
               {
                       "name": "YOUR_PROJECT_NAME",
                       "program": "lib/main.dart",
                       "request": "launch",
                       "type": "dart",
                       "args": [
                               "--no-sound-null-safety"
                           ]
               }
       ]
}
  1. flutter test中设置
    Code => Preferences => Settings => Search setting, type in “flutter test” => Dart: Flutter Test Additional Args, Add item => Add “–no-sound-null-safety”

在这里插入图片描述

  • IntelliJ IDEA/Android Studio

Run --> Edit Configurations --> Add Additional Run args --> --no-sound-null-safety
在这里插入图片描述
在这里插入图片描述

参考

  1. 【译】Flutter 1.20 中悄然带来的 null safety

  2. Cannot run with sound null safety because dependencies don’t support null safety

扫码关注公众号:35知己

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值