我正在制作第一个使用Flutter构建Android应用程序的应用程序。我正在使用Android Studio作为IDE。问题是当我导入http包时:
import 'package:http/http.dart' as http;
Run Code Online (Sandbox Code Playgroud)
我得到一个错误:
错误:URI目标不存在:“ package:http / http.dart”。(uri_does_not_exist位于[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);
}
Run Code Online (Sandbox Code Playgroud)
谢谢,
您需要按照以下说明将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
Run Code Online (Sandbox Code Playgroud)
添加依赖性后,您需要运行以下命令来更新/安装所需的软件包:
flutter packages upgrade
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助
确保您已将依赖项添加到 pubspec.yaml
dependencies:
http: ^0.12.0
Run Code Online (Sandbox Code Playgroud)
您还需要:
flutter packages get
| 归档时间: |
|
| 查看次数: |
4366 次 |
| 最近记录: |