颤振Dart:URI的目标不存在 [英] Flutter | Dart : Target of URI does not exist

查看:60
本文介绍了颤振Dart:URI的目标不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作我的第一个应用程序,以使用Flutter构建Android应用程序。
我正在使用Android Studio作为IDE。
问题是当我导入http软件包时:

I am making my first Application to build an Android App with Flutter. I am using Android Studio as IDE. The problem is when I import the http package:

 import 'package:http/http.dart' as http;

我遇到错误:


错误:URI的目标不存在:'package:http / http.dart'。
(uri_does_not_exist at [flutter_crypto] lib\home_page.dart:3)

error: Target of URI doesn't exist: '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中。

You need to add the HTTP dependency to pubspec.yaml as per below.

 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

添加依赖项之后,您需要运行以下命令来更新/安装所需的软件包:

With the dependency added you then need to run the following command to update/install required packages:

flutter packages upgrade

希望这会有所帮助

这篇关于颤振Dart:URI的目标不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆