颤振 Dart:URI的目标不存在

Mas*_*nge 4 flutter

我正在制作第一个使用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)

谢谢,

Phu*_*hib 9

您需要按照以下说明将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)

希望这可以帮助

  • 使用 VS Code,最后您可能还需要重新启动 IDE (3认同)

Ric*_*eap 7

确保您已将依赖项添加到 pubspec.yaml

dependencies:
  http: ^0.12.0
Run Code Online (Sandbox Code Playgroud)

您还需要:

flutter packages get