我刚把我的Macbook设置为扑动显影,

所以我下载了flutter SDK,并把它放在我的文档中。之后,我在命令行中设置了path变量来使用flutter。

我执行命令flutter create todolist,这样我就实现了一个空白项目。

我还用Dart-Code设置了我的visual studio代码,这样我就有了正确的语法高亮,智能感知等。

所以当我打开visual studio代码时,它会突出显示导入方法,如下图所示:

这意味着它还会突出显示正确的类,从而完全难以理解它是否是一个真正的错误。

我已经执行了pub get和flutter包get,并正确地得到了所有内容。 我的路径变量都是正确的。

为什么它突出显示它无法找到“导入”包?


当前回答

我也有这个问题。我的系统中同时安装了VS code和Android studio。

错误是在VS代码中。

当我在Android studio上打开同一个项目时,依赖项实际上并没有添加到pubsec.yaml中。我把它加进去,然后运行pub。get。

当我回到VS Code时,一切都很好。

所以,试着在其他编辑器中打开它,如果你有,或者通过记事本。

编辑:

打开widget_test。飞镖和运行它也应该解决你的问题。

其他回答

让Dart-Code可靠地找到您的Flutter安装和使用它的最快方法是创建一个新的FLUTTER_ROOT环境变量,并将其设置为您的Flutter路径。

当你通常得到这样的错误信息:

URI的目标不存在:'package:foo'。尝试创建文件 或尝试对确实存在的文件使用URI。

例子:

URI的目标不存在: “包:random_string / random_string.dart”。尝试创建文件 或尝试对确实存在的文件使用URI。

import 'package:random_string/random_string.dart';

这是因为缺少一个依赖项。

所以你所要做的就是通过google你的包名来找出需要什么包。

安装依赖项:

$ flutter pub get

并在pubspec中添加依赖项。yaml文件:

I was using (goggle location picker (with much more customisation in functions and UI) ) so I copy this package(complete) and using in my app in one folder but since dart code analyser analyses one flutter project so I found that those which are referencing from inside of this package is not working then I copy only lib folder(of google location picker) in my original project folder and voila this worked for me. This solution took me a time of 3 days. I know this is not the question but it might help someone to save 3 days.

去pubsec。在cupertino_icons后直接添加Yaml文件:

webview_flutter:

然后按右上角的Packages get,它就会很好地为你工作。

我也有这个问题。我的系统中同时安装了VS code和Android studio。

错误是在VS代码中。

当我在Android studio上打开同一个项目时,依赖项实际上并没有添加到pubsec.yaml中。我把它加进去,然后运行pub。get。

当我回到VS Code时,一切都很好。

所以,试着在其他编辑器中打开它,如果你有,或者通过记事本。

编辑:

打开widget_test。飞镖和运行它也应该解决你的问题。