Auto-import for Dart extension methods

Felix Blaschke
2 min readDec 1, 2020

Exactly one year ago I started my supercharged package. It’s goal is to add some comfort to Flutter and Dart developers by adding some quality of life extension methods.

I am using it within my own project and stumbled over an issue that hasn’t been fixed yet. Maybe you already noticed it yourself:

You can not auto-import a package by just using it’s extension method:

No autofix for importing supercharged.dart

Now after one year of extension methods in Dart. Why isn’t this fixed? According this issue from October 2019 it needs to be addressed in the Dart Analysis Server. It sounds like the Dart team is busy with null-safety.

Now there are two things you can do:

  • Press the 👍 emote in the issue to raised the awareness.
  • Upgrade to supercharged to 1.12.0 that I released today.

I added a class Supercharged without any function. But you can use it to trigger the auto-import:

  • Start typing “Superch” and press Ctrl + Space for autocomplete to trigger the import.
  • Remove the line and continue coding with supercharged power!
Auto-Import working

You can find the latest version of supercharged in pub.dev. I also updated it’s little Dart-only brother supercharged_dart.

If you are a package developer feel free to use this trick until the issue is fixed.

Leave some claps and until next time
— Felix —

--

--