简体   繁体   English

Dart 2.1中的HTTP包发生了什么?

[英]What happened with HTTP package in Dart 2.1?

With dart 2.0 and lower I was able to import the HTTP package directly without modifying my pubspec.yaml file. 使用dart 2.0和更低版本,我可以直接导入HTTP包而无需修改pubspec.yaml文件。

I've opened an old project and I've got the error: "Your application could not be compiled, because its dependencies could not be established. That library is in a package that is not known. Maybe you forgot to mention it in your pubspec.yaml file?" 我打开了一个旧项目,我得到了错误:“你的应用程序无法编译,因为它的依赖关系无法建立。那个库在一个未知的包中。也许你忘记在你的pubspec.yaml文件?“

I had to go to pubpect.yaml file, and under dependencies I've added: "http: ^0.12.0" to make my project work again. 我不得不去pubpect.yaml文件,在依赖项下我添加了:“http:^ 0.12.0”让我的项目再次运行。

What happened, why was the HTTP package removed from dart core libraries? 发生了什么,为什么从dart核心库中删除了HTTP包?

https://github.com/flutter/flutter/wiki/Changelog#v025 https://github.com/flutter/flutter/wiki/Changelog#v025

v0.2.5 v0.2.5

#15416 removed package:http from Flutter and replaced all usages with the HttpClient from dart:io. #15416删除了包:来自Flutter的http并用来自dart:io的HttpClient替换了所有用法。 If you use package:http you must add it as a dependency in your pubspec.yaml to continue using it. 如果您使用package:http,则必须将其作为pubspec.yaml中的依赖项添加才能继续使用它。

See https://github.com/flutter/flutter/wiki/Changelog#v025 请参阅https://github.com/flutter/flutter/wiki/Changelog#v025

As the flutter has removed the http from dart.io, you can't directly use it without specifying the dependency in pubspec.yaml file. 由于flutter已从dart.io中删除了http,因此如果不在pubspec.yaml文件中指定依赖项,则无法直接使用它。 open the flutter project and add the http library dependency as given below, 打开flutter项目并添加http库依赖项,如下所示,

dependencies:
  flutter:
    sdk: flutter
  shared_preferences: "^0.4.2"
  http: ^0.12.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM