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

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

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

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

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

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

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

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


当前回答

添加依赖关系。 例如:- import 'package:audioplayers/audio_cache.dart'; 在上面的包中,如果我们只使用这个包,那么它会显示错误 但是如果我们在pubspec.yaml中添加依赖项 如

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

然后单击packages get。

正如你所看到的,我也可以插入依赖项,所以如果你在包中插入依赖项,那么你就可以开始了。

其他回答

我也遇到了同样的问题,在我重新启动visual studio后,我再次使用flutter pub添加bloc安装了包,这次安装正确。请注意,我试着安装了几次,这一次它是一个魅力

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

我在Android Studio的rflutter_alert包中遇到了这个问题。插入依赖项后,我用ctrl+空格键将包导入到我的项目中,并添加了import 'package:rflutter_alert/';问题是这是不正确的。正确的形式是package:rflutter_alert/rflutter_alert.dart 对与错的比较

重新启动visual studio代码对我有用!

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.