可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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 work with flutter in my command line.
I execute the command flutter create todolist
so I achieve a blank project.
I also setup my visual studio code with Dart-Code so I have the proper syntax highlight, intellisense, etc.
So when I open visual studio code, it highlights the import
method, like the following image:
This means that it also highlights the classes that are correct, making it completely hard to understand if its a real error or not.
I have executed both pub get
and flutter packages get
and got everything correctly.
I have my path variables all correctly.
Why is it highlighting it cannot find that 'import' package?
回答1:
Restarting Visual Studio Code after flutter packages get
resolved the error messages for me.
回答2:
Just run
flutter packages get
and restart VISUAL CODE STUDIO.
It will work fine.
回答3:
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.
回答4:
flutter clean
flutter packages get
flutter packages upgrade ( Optional - use if you want to upgrade packages )
Restart Android Studio or Visual Studio
回答5:
open terminal from the project directory
and run
flutter packages get
when its done wait for some minute let the IDE reload itself
回答6:
The quickest way to get Dart-Code to reliably find your Flutter install and use it is to create a new FLUTTER_ROOT
environment variable and set it to your Flutter path.
回答7:
If you have used the flutter packages get
command and the error still persists, you can simply reload VS code the Developer: Reload Window
command. Simply type that in after pressing Ctrl+Shift+P
(Cmd+Shift+P
for Mac users). It will clear the error. It's like refreshing VS Code.
回答8:
Open the command palette (ctrl+shift+p), type flutter: get packages (should autocomplete); after it resolves open the command palette again and type reload window and execute the command. This should resolve the issue as quickly as possible.
回答9:
Just run
flutter pub get
and restart VISUAL CODE STUDIO.
It will work fine.
回答10:
Also happened to me while trying to run the project inside of another directory.
Worked by using the root directory of the main project
回答11:
Just add
dependencies:
http: ^0.12.0
in pubspec.yaml file
please check http documentation
回答12:
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.
回答13:
Execute one of the following:
flutter upgrade
flutter pub get
flutter packages get
回答14:
Warning! This package referenced a Flutter repository via the
.packages file that is no longer available. The repository from which
the 'flutter' tool is currently executing will be used instead.
running Flutter tool: /opt/flutter previous reference :
/Users/Shared/Library/flutter This can happen if you deleted or moved
your copy of the Flutter repository, or if it was on a volume that is
no longer mounted or has been mounted at a different location. Please
check your system path to verify that you are running the expected
version (run 'flutter --version' to see which flutter is on your
path).
Checking the output of the flutter packages get
reveals that the reason in my case was due to moving the flutter sdk.
回答15:
Do not forget:
export PATH="$PATH:/home/[xxxxx]/flutter/bin
For me, it works:
flutter upgrade
flutter packages get
You can check with
flutter doctor
flutter --version
回答16:
Go to pubsec.yaml file and add this directly after cupertino_icons:
webview_flutter:
Then press Packages get on the top right corner and it will work fine with you.
回答17:
Don't forget to save pubspec.yaml before running "flutter pub get". Restarting Visual Studio Code is not enough. That was my solution. Sometimes when you work with intellij you forget that ...