5

Recently got started with Flutter 1.0.0. flutter doctor -v no issues Been deploying to an iOS device no worries.

Problem started when I tried to add Dart Packages via the pubspec.yaml file. No packages are installing and it outputs only exit code 0 in VS Code. The extension button at the top of the pubspec.yaml file does not work either.

imports are showing with red underlines and 'URI undefined' so the packages are definitely not downloading and installing.

Any help much appreciated!

Pubspec.yaml file:

name: http_l
description: A new Flutter project.

version: 1.0.0+1

environment:
  sdk: ">=2.0.0-dev.68.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  http: ^0.12.0

dev_dependencies:
  flutter_test:
    sdk: flutter

    flutter:
  uses-material-design: true

and the main.dart file has a red underlined import:

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

with error message:

Target of URI doesn't exist: 'package:http/http.dart'.dart(uri_does_not_exist)
Mike Soertsz
  • 61
  • 1
  • 4
  • are you inside a closed network or proxy?? – Subramanya Chakravarthy Dec 17 '18 at 06:51
  • 2
    "exit code 0" means all went fine. Perhaps you have no dependencies in `pubspec.yaml` or not added in the correct way. Please post your `pubspec.yaml`. – Günter Zöchbauer Dec 17 '18 at 06:57
  • Could you please post a sample of your code? As pointed out by @GünterZöchbauer `exit code 0` means all worked fine. So the problem is somewhere else. Maybe you have imported a library but forgot to add `as URI;` at the end? – shadowsheep Dec 17 '18 at 08:32
  • @SubramanyaChakravarthy not inside a proxy no. – Mike Soertsz Dec 18 '18 at 18:49
  • @GünterZöchbauer added pubspec and only a single dependancy added (http) which doesn't appear to be working. – Mike Soertsz Dec 18 '18 at 18:50
  • Looks all fine. No idea where the error comes from. You could try `flutter package pub cache repair` and deleting `~/.dartServer/.analysis-driver/`(you'd have to figure out yourself where that is exactly if you use Windows) – Günter Zöchbauer Dec 19 '18 at 05:42
  • Does restarting VS Code make the error go away? I think sometimes the server doesn't detect package changes. If a restart fixes it, then it's likely a known issue. If not, it must be something else. – Danny Tuppeny Feb 22 '19 at 16:52
  • Possible duplicate of [Visual Studio Code - Target of URI doesn't exist 'package:flutter/material.dart'](https://stackoverflow.com/questions/44909653/visual-studio-code-target-of-uri-doesnt-exist-packageflutter-material-dart) – griffins Aug 17 '19 at 17:16

2 Answers2

4

install this plug in on vs-code
Pubspec Assist or download from hare form this link

click ctrl+shift+p connend pubspag write your dependency it will fix the error

mastisa
  • 1,875
  • 3
  • 21
  • 39
Kalyan Biswas
  • 350
  • 1
  • 3
  • 10
1

Since I encountered this recently, here is what causes the problem:

Visual Studio Code does NOT automatically save your pubspec.yaml file when running pub get.

You can fix the problem of it not getting packages by simply going to File>Save (Ctrl+S), after making changes to it, and before running pub get.

Zyon900
  • 11
  • 1