MasterSinge
MasterSinge

Reputation: 675

Flutter | Dart : Target of URI does not exist

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;

I get an error :

error: Target of URI doesn't exist: 'package:http/http.dart'. (uri_does_not_exist at [flutter_crypto] lib\home_page.dart:3)

That's my code :

  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,

Upvotes: 12

Views: 36437

Answers (4)

Alireza Ebrahimi
Alireza Ebrahimi

Reputation: 1

run: dart pub --trace get --no-precompile in android srudio Terminal

Upvotes: 0

Richard Heap
Richard Heap

Reputation: 51751

Make sure you have added the dependency to pubspec.yaml

dependencies:
  http: ^0.12.0

You will also need to:

flutter packages get

Upvotes: 8

Ahmed Saied
Ahmed Saied

Reputation: 271

For any upcoming problem with importing packages from dart please go to official Dart website packages and search for needed package and you will find solution up there.


for your issue go to:

  1. https://pub.dartlang.org/packages/http
  2. Installing tap https://pub.dartlang.org/packages/http#-installing-tab-
  3. follow guide steps:

    In pubspec.yaml file:@ dependencies

     dependencies:
         http: ^0.12.0
         flutter:
    

(NB: please make sure that http & flutter or any other attribute inside dependencies are aligned as above and they are at same line)


In terminal run below command:

$flutter packages get

Upvotes: 3

Phuthib
Phuthib

Reputation: 1446

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

Hope this helps

Upvotes: 32

Related Questions