我正在制作我的第一个应用程序来使用 Flutter 构建 Android 应用程序。
我使用 Android Studio 作为 IDE。
问题是当我导入 http 包时:
import 'package:http/http.dart' as http;
我收到错误:
错误: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);
}
Thanks,
您需要将 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
希望这可以帮助
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)