Android Studio no longer autocompletes certain imports

Issue

After having updated Android Studio to Chipmunk | 2021.2.1 Patch 1, and migrated some of my projects to null safety and done lots of stuff, I suddenly noticed that when I start typing an import name, Android Studio no longer fills in the full file name, the way it used to! Like if I type:

import 'mat'

it used to suggest to fill in:

import 'package:flutter/material.dart';

but it no longer does! Instead, it suggests:

import 'dart:math';

so… it finds Dart packages but not Flutter packages? Even if I download a Flutter package by depending on it in the pubspec.yaml file and running flutter pub get, autocomplete does not seem to find it. I have to write the full file name.

I’ve also noticed that if I’m in a file in a sub folder of my lib folder, say in lib/screens/screen_a.dart, and there is also a screen_b.dart in that sub folder, I can start typing:

import 'scr';

and AS will suggest:

import 'screen_b.dart';

just as it used to. All very well. But if I want to import a file from a different sub folder, such as cool_widget.dart from lib/widgets/, I used to type:

import 'widgets';

and it would fill in:

import 'package:my_project_name/widgets/';

from which I could type:

import 'package:my_project_name/widgets/coo';

and get the whole file name:

import 'package:my_project_name/widgets/cool_widget.dart';

That no longer happens! Instead, I now have to type the entire path above before Android Studio seems to recognize it…

I also don’t get any autocomplete suggestions for project files within the lib folder if I’m in the lib folder. It’s only if I’m in a sub folder that I get any suggestions for project files, and only from within that same sub folder. This is very difficult, as it slows down the import process considerably.

The problem of not finding other project files is there in several of my projects, including those I haven’t yet migrated to null safety, but not in all. The problem of not finding Flutter packages but finding Dart packages also seems to be there only in some projects, and not necessarily the same as above…

I really can’t say what I did that triggered this… Please help?

Things I’ve tried

I’ve done flutter clean and Invalidate caches and restart. I’ve also deleted a number of build files and directories, including the entire .gradle directory (several GB), and restarted, but nothing helped.

I’ve also looked through all my settings to see if there’s something there, but I didn’t find anything obvious…

Solution

This problem is caused by regressions in the new completion protocol introduced in a recent Dart version.

The fix has been implemented in this commit, and will be included in Dart 2.18.

This fix, along with a slew of other autocompletion fixes, are also in the process of being cherry-picked into the stable channel here.

Answered By – hacker1024

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *