Dart-code: Support auto import for extension methods

Created on 29 Mar 2020  Â·  10Comments  Â·  Source: Dart-Code/Dart-Code

Currently if I want to call a extension method, I can't just auto import with the quick fix.

numberFormat.formatAllowNull(widget.value)

In the example the method "formatAllowNull" is a extension method, but clicking on the bulb doesn't provide the option to auto import it. Is this something that will be supported?

upstream in dart / flutter

Most helpful comment

It's been over a year, and this issue still exist☹

All 10 comments

Thanks for the suggestion! The quick-fixes come from the analyzer in the SDK, so this would need to be implemented there. It seems like that's already been done (dart-lang/sdk#38894) but it might not have made a stable release yet.

If it's not working for you on latest dev/master branches, let me know. Thanks!

This isn't working for me. If I create a new project and add a file with an extension, eg:

extensions.dart

import 'package:flutter/material.dart';

extension TestContextExt on BuildContext {
  void blah() {
    print('blah');
  }
}

I can use the extension function if I manually add import 'extensions.dart'; but clicking on the bulb or using Cmd ., I get no "Import library..." option.

flutter doctor
[✓] Flutter (Channel master, 1.18.0-11.0.pre.6, on Mac OS X 10.15.4 19E287,
locale en-AU)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.44.2)
[✓] Connected device (5 available)

@nickmeinhold thanks, I've comment on https://github.com/dart-lang/sdk/issues/38894 - I suspect that issue will be re-opened.

I still experience the same issue with Dart 2.10.1

@behnam-lum the issue linked above is still open, so this hasn't been resolved yet.

This issue was closed as there's nothing to do here, once fixed in the SDK it will show up here automatically.

Following

Still waiting for it to be implemented

I have the same issue.

I really need to update this feature soon

It's been over a year, and this issue still exist☹

Was this page helpful?
0 / 5 - 0 ratings