Flutter auto importing extension file is not working

Viewed 970

I have a simple String-Extension which looks like this:

extension TranslationHelper on String {
  String localized() {
    return AppLocalizations(Locale('de', 'DE')).translate(this);
  }
}

With this I am able to call .localized() on any String.

Problem: Flutter or VSCode is not auto-importing the file for me and also not suggesting it with a Quick-Fix. Importing the file manually is quite painful. Is this a bug or what am I missing here?

All other importing works perfectly fine...

1 Answers

This is a known issue, and is being tracked.

As a workaround, typing the name of the extension should let you auto import it. For example, with the following extension, typing MyExtension should allow you to import it.

extension MyExtension on Object {
  void doSomething() {}
}
Related