Visual Studio Code - Target of URI doesn't exist 'package:flutter/material.dart'

后端 未结 29 886
Happy的楠姐
Happy的楠姐 2020-12-07 21:33

I\'ve just setup my Macbook for flutter development,

So I downloaded flutter sdk, and placed it in my Documents. After, I setup my path variable to

相关标签:
29条回答
  • 2020-12-07 22:12

    Just add dependencies: http: ^0.12.0 in pubspec.yaml file please check http documentation

    0 讨论(0)
  • 2020-12-07 22:12

    try to run flutter clean

    then restart VS Code. This did it for me.

    0 讨论(0)
  • 2020-12-07 22:13

    Add dependencies. for example:- import 'package:audioplayers/audio_cache.dart'; in the above package if we only use this package then it shows error but if we add dependencies in pubspec.yaml such as

    dependencies:
        flutter:
          sdk: flutter
        cupertino_icons: ^0.1.2
        audioplayers: ^0.14.1
    

    enter image description here

    then click on packages get.

    as you see this, I can also insert dependencies so if you insert dependencies along with your package then you are good to go.

    0 讨论(0)
  • 2020-12-07 22:14

    When you usually get this error message:

    Target of URI doesn't exist: 'package:foo'. Try creating the file referenced by the URI, or Try using a URI for a file that does exist.

    Example:

    Target of URI doesn't exist: 'package:random_string/random_string.dart'. Try creating the file referenced by the URI, or Try using a URI for a file that does exist.

    import 'package:random_string/random_string.dart';
    

    It is because a dependency is missing.

    So all you have to do is find out what packages are needed by googling your package name.

    Install the dependency:

    $ flutter pub get
    

    and add the dependency in the pubspec.yaml file:

    0 讨论(0)
  • 2020-12-07 22:15

    Author of the Dart Code plugin here! From the screenshot, I would say this is because your flutter project is in a sub-folder of the folder open in Code. We only scan the opened-folder to check whether it's a Flutter project - which then changes the SDK we launch and also enables the Flutter functionality (like the daemon and debugger).

    You should re-open the "todo" folder directly.

    If you want to have multiple projects open together, use multi-root workspaces, since Dart Code is multi-root-aware and will check each of the folders in the workspace when deciding if it needs to enable Flutter functionality.

    Update

    This case should be better supported in the Dart plugin now, so opening the immediate parent folder of a Flutter project should work as expected.

    0 讨论(0)
  • 2020-12-07 22:15

    If you execute From the terminal: "Run flutter packages get" and the error continues, check is all packages directories are listed at '.packages' file. - Sometime you have the packages, but it is not configured at this file.

    0 讨论(0)
提交回复
热议问题