Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to autocomplete/import Flutter classes in IntelliJ?

In IntelliJ, I have to manually import Flutter packages at the top of the file in order for auto-complete to work elsewhere in the file.

I was rather hoping I could start typing something (in a method) and IntelliJ would search my pubspec.yaml and locally within my project and suggest classes I might want. If I selected something that wasn't already imported, it should import it for me.

This basic functionality is available in many other languages and IDEs, so I'm wondering if I've got something misconfigured. I'm using IntelliJ 2018.2 with the latest Flutter and Dart plugins installed.

like image 711
Duncan Jones Avatar asked Sep 20 '18 13:09

Duncan Jones


People also ask

How to use auto import in IntelliJ IDEA?

Auto-import There are several options in IntelliJ IDEA that we may configure in Settings > Editor > Auto Import: Let's review each of these options. 2.1. Show Import Popup

How do I import packages instead of single classes in IntelliJ?

Import packages instead of single classes. IntelliJ IDEA suggests to import single classes by default. You can change the settings to import entire packages instead. In the Settings/Preferences dialog (Ctrl+Alt+S), select . Clear the Use single class import checkbox, and apply the changes.

How do I enable auto import for classes?

When looking for a command/keyboard shortcut, type Ctrl-shift-A (or Cmd-shift-A on Mac), and search for the command. For example here, typing "imports" will show you the command "Optimize imports", and its keyboard shortcut. The auto import for classes is working if you enable it under "Settings > Editor > General > Auto Import".

How do I get code completion in IntelliJ?

After the new keyword in an object declaration Start typing. By default, IntelliJ IDEA displays the code completion popup automatically as you type. If automatic completion is disabled, press Ctrl+Shift+Space or choose Code | Code Completion | Type-Matching from the main menu.


1 Answers

This is a known issue.

For performance reasons the DartAnalyzer was built to only load libraries that were imported anywhere in the projects code already. The overall performance of DartAnalyzer was improved a lot since then and it would now allow to provide better suggestions, but it seems there weren't enough resources available yet to get it implemented.

Upvote and follow https://github.com/dart-lang/sdk/issues/25820

like image 113
Günter Zöchbauer Avatar answered Sep 17 '22 14:09

Günter Zöchbauer