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

flutter run 运行报错Error: Cannot run with sound null safety,第1张

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 在.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"
                           ]
               }
       ]
}
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

参考

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

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/996460.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存