Can’t import ‘package:http/http.dart’ as http; in project’

ForumCategory: QuestionsCan’t import ‘package:http/http.dart’ as http; in project’
chartyem asked 6 months ago

Added in main.dart

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

And in pubspec.yaml

  • dependencies:
  • flutter:
    sdk: flutter
    http: ^0.12.0+2

    But DartAnalysis: write

    error: Target of URI doesn't exist: 'package:http/http.dart'. (uri_does_not_exist at [network_terminal] lib/main.dart:2)

    Then I try

    Terminal:$ flutter packages get

    DartAnalysis:

    Running "flutter packages get" in network_terminal...
    Error on line 21, column 5 of pubspec.yaml: A dependency may only have one source.

    21 │ ┌ sdk: flutter
    22 │ │ http: ^0.12.0+2

    23 │ │ # The following adds the Cupertino Icons font to your application.
    24 │ │ # Use with the CupertinoIcons class for iOS style icons.
    25 │ │ cupertino_icons: ^0.1.2
    │ └──^

    pub get failed (65)

    Then try

    Terminal:$ flutter packages upgrade

    DartAnalysis:

    Running "flutter packages upgrade" in network_terminal...
    Error on line 21, column 5 of pubspec.yaml: A dependency may only have one source.


    21 │ ┌ sdk: flutter
    22 │ │ http: ^0.12.0+2
    23 │ │ # The following adds the Cupertino Icons font to your application.
    24 │ │ # Use with the CupertinoIcons class for iOS style icons.
    25 │ │ cupertino_icons: ^0.1.2
    │ └──^

    pub upgrade failed (65)

    I don’t understand, how to move on

    Terminal:$ flutter doctor

    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel master, v1.5.9-pre.43, on Linux, locale en_US.UTF-8)

    [✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    [✓] Android Studio (version 3.4)
    [!] Connected device
    ! No devices available

    ! Doctor found issues in 1 category.

    Terminal:$ flutter doctor -v

    [✓] Flutter (Channel master, v1.5.9-pre.43, on Linux, locale en_US.UTF-8)
    • Flutter version 1.5.9-pre.43 at /home/chartyem/development/flutter
    • Framework revision 3cd15b52d4 (5 days ago), 2019-04-27 04:52:18 -0400
    • Engine revision 3b1bebf289
    • Dart version 2.3.0 (build 2.3.0-dev.0.3 c46deebfb6)

    [✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /home/chartyem/Android/Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /home/chartyem/development/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b16-5323222)
    • All Android licenses accepted.

    [✓] Android Studio (version 3.4)
    • Android Studio at /home/chartyem/development/android-studio
    • Flutter plugin version 35.0.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b16-5323222)

    [!] Connected device
    ! No devices available

    ! Doctor found issues in 1 category.

    2 Answers
    patel.krunal answered 1 month ago

    Maybe Your Solution Here

    patel.krunal answered 1 month ago

    Go to your pubspec.yaml file , and add the http dependency:

    dependencies:
    flutter:
    sdk: flutter
    
    cupertino_icons: ^0.1.2
    http: any

    Remember, the indentation must be the same as ‘flutter’ or ‘cupertino_icons’
    And don’t forget to run this command in your terminal :

    flutter packages get

    Founded At Here