首页 > 解决方案 > 颤振 | 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);
  } 

谢谢,

标签: flutterhttpdartpackagedependencies

解决方案


您需要将 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

希望这可以帮助


推荐阅读