简体   繁体   English

VS Code 和 Flutter/Dart,小部件自动完成功能不起作用

[英]VS Code and Flutter/Dart, Widget Autocomplete not working

I'm working with some tutorials to learn Flutter and the one that I'm taking now uses VSCode.我正在使用一些教程来学习 Flutter,而我现在正在学习的教程使用 VSCode。 I actually prefer it to Android Studio because it doesn't overheat my Macbook.实际上,我更喜欢它而不是 Android Studio,因为它不会使我的 Macbook 过热。 The only frustration I've had with it so far is that there are quite a few times where autocomplete just stops working.到目前为止,我唯一感到沮丧的是,有好几次自动完成功能停止工作。 For instance, if I wrap a Column in a widget and then start typing Container, Android Studio will pop up an autocomplete showing Container VS Code used to do this for me, but has stopped for some reason.例如,如果我将 Column 包装在一个小部件中,然后开始键入 Container,Android Studio 将弹出一个自动完成功能,显示 Container VS Code 曾经为我执行此操作,但由于某种原因已停止。 I can still get the autocomplete list if I press Ctrl+Spacebar.如果按 Ctrl+空格键,我仍然可以获得自动完成列表。

I'm using the following:我正在使用以下内容:

  • VS Code - 1.36.1 VS 代码 - 1.36.1

  • Dart Extension - 3.2.0 Dart 分机 - 3.2.0

  • Flutter Extension - 3.2.0 Flutter 分机 - 3.2.0

  • Material Icon Theme - 3.8.0材质图标主题 - 3.8.0

This is the latest version for all of these.这是所有这些的最新版本。

Is there some setting or something that I need to change?是否有一些设置或我需要更改的内容? I've spent the last two hours trying to work out what's going on.在过去的两个小时里,我一直在努力弄清楚发生了什么。 In searching, I did see some references to earlier versions of VS Code and the extensions causing problems, but nothing about these versions.在搜索中,我确实看到了一些对早期版本的 VS Code 和导致问题的扩展的引用,但没有关于这些版本的信息。

Go to pubspec.yaml and hit save or run get packages.转到 pubspec.yaml 并点击保存或运行获取包。 It worked for me, hope it helps它对我有用,希望它有帮助

There are generally two reasons for VS Code to automatically open code completion - 1) when you press a key that the extension ahs told VS Code should invoke it and 2) when VS Code thinks it would be useful (for example when you start typing on a blank line). VS Code 自动打开代码完成通常有两个原因 - 1) 当您按下扩展 ahs 告诉 VS Code 应该调用它的键时,以及 2) 当 VS Code 认为它有用时(例如,当您开始输入时)一个空行)。 If you're typing in a line of existing code it won't always do this.如果您输入一行现有代码,它不会总是这样做。

Pressing Ctrl+Space is the correct way to open completion in the cases where it doesn't appear automatically.在未自动出现的情况下,按 Ctrl+Space 是打开完成的正确方法。

That said, if you can provide more information about a specific instance, I can take a look if it's something we could/should pop completion open for.也就是说,如果您可以提供有关特定实例的更多信息,我可以看看它是否是我们可以/应该打开完成的东西。 It would be best raised at https://github.com/Dart-Code/Dart-Code/issues with a screenshot and details of exactly where your cursor is (and how you got there).最好在https://github.com/Dart-Code/Dart-Code/issues上提出,并附上屏幕截图和光标确切位置的详细信息(以及如何到达那里)。

不要使用太多的flutter扩展,我也面临这个问题,然后我意识到安装了3个flutter扩展,只使用一个,对我有用,试试看。

I did have a derivative of this problem when I was working with VS Code and flutter and this is what I did.当我使用 VS Code 和 flutter 时,我确实遇到了这个问题的衍生物,这就是我所做的。 This is for windows though.不过这适用于窗户。 This is what I did ;这就是我所做的; Go to C:\\Users<your username >\\AppData\\Roaming\\Code and delete all the files and the directory called "Code".转到 C:\\Users<您的用户名 >\\AppData\\Roaming\\Code 并删除所有文件和名为“Code”的目录。 Usually the folder AppData is hidden so you'll have to unhide it.通常文件夹 AppData 是隐藏的,所以你必须取消隐藏它。 Then restart your computer and then reopen VS Code.然后重新启动计算机,然后重新打开 VS Code。 This I think cleared some of the unwanted cache files which kind of made things right again.我认为这清除了一些不需要的缓存文件,这让事情再次变得正确。 Hope it helped.希望它有所帮助。

PAY ATTENTION!!请注意!! Check if your operation system take the same shortcut that the VSCODE Intellisense use for code completion.检查您的操作系统是否采用与 VSCODE Intellisense 用于代码完成相同的快捷方式。 For example: if the Operational System of your laptop use control+space for change the input language of your keyboard, this shorcut will work for operational system only.例如:如果您的笔记本电脑的操作系统使用 control+space 来更改键盘的输入语言,则此快捷方式仅适用于操作系统。 It's need to disable in the settings keyboard.需要在设置键盘中禁用。 After this, the intellisense autocomplete must work well.在此之后,智能感知自动完成必须运行良好。 It's works for me!它对我有用!

Doing a flutter clean and then flutter pub upgrade worked for me.清洁 flutter 然后 flutter pub 升级对我有用。 Sometimes flutter clean using the command line does not work if you have android studio then in tools go to flutter and then do flutter clean. Sometimes flutter clean using the command line does not work if you have android studio then in tools go to flutter and then do flutter clean.

Make sure确保

Preferences > Editor > Intentions > Quick assist powered by the Dart Analysis Server首选项 > 编辑器 > 意图 > 由 Dart 分析服务器提供支持的快速协助

is enabled ( Screenshot ).已启用(屏幕截图)。

If so, most likely your Dart Analysis server is crashing.如果是这样,很可能您的 Dart 分析服务器正在崩溃。 Navigate to your HOME folder:导航到您的 HOME 文件夹:

cd ~

And then below should resolve your issue:然后下面应该可以解决您的问题:

sudo chown -R $USER .dart .flutter

Clear your cache if the issue still exists:如果问题仍然存在,请清除缓存:

File > Invalidate Caches > Clear file system cache and Local History > Invalidate and Restart.

Also, Power Save Mode should be disabled:此外,应禁用省电模式:

File > Power Save Mode

just do flutter clean then flutter create.只需清洁 flutter 然后 flutter 创建。 and then flutter pub upgrade, and also see if your flutter SDK is latest or not.然后 flutter pub 升级,并查看您的 flutter SDK 是否是最新的。

Check to make sure Android Studio is not on low power mode检查以确保 Android Studio 未处于低功耗模式

Menu>File>Low Power Save Mode菜单>文件>低功耗模式

I solved in in my Macbook Pro by我在我的 Macbook Pro 中解决了

Going to System Preferences > Keyboard > Shortcuts > Input Sources转到系统偏好设置>键盘>快捷方式>输入源

Disable: Select the previous input source (^ space)禁用:Select 上一个输入源(^空格)

Updating VS Code dart and flutter extensions更新 VS Code dart 和 flutter 扩展

Restarting the computer.重新启动计算机。

And voila.瞧。 Ctrl + space now shows options in VS Code. Ctrl + 空格现在显示 VS Code 中的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM