flutter - 颤振 | Dart:URI的目标不存在
问题描述
我正在制作我的第一个应用程序来使用 Flutter 构建 Android 应用程序。我正在使用 Android Studio 作为 IDE。问题是当我导入 http 包时:
import 'package:http/http.dart' as http;
我收到一个错误:
错误:URI 的目标不存在:'package:http/http.dart'。(uri_does_not_exist at [flutter_crypto] lib\home_page.dart:3)
那是我的代码:
Future<List> getCurrencies() async{
String cryptoUrl = "https://api.coinmarketcap.com/v1/ticker/?limit=50";
http.Response response = await http.get(cryptoUrl);
return JSON.decode(response.body);
}
谢谢,
解决方案
您需要将 HTTP 依赖项添加到 pubspec.yaml,如下所示。
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
http: ^0.12.0
添加依赖项后,您需要运行以下命令来更新/安装所需的软件包:
flutter packages upgrade
希望这可以帮助
推荐阅读
- apache-kafka - Kafka compare consecutive values for a key
- node.js - How to shift a particular document from one collection to another using mongoose?
- java - 为什么将null分配给节点不会删除链表中的该节点
- css - How to use parent div font color instead of child
- javascript - how to quick up the process of displaying images in React coming from backend (Django Rest)
- python - Difference in run time complexity of two seemingly similar solutions
- javascript - node.js中的through2和native Transform流有什么区别?
- file-upload - 如何使用按钮标签以无头模式上传文件
- unit-testing - 如何对 Umbraco Api 控制器进行单元测试 - System.ArgumentNullException:'值不能为空。参数名称:umbracoContext'
- android - How to update existing line layer in MapBox