dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.57k forks source link

Suggest imports from custom directories #49137

Open hyungtaecf opened 2 years ago

hyungtaecf commented 2 years ago

Issue Description

I'm using auto-generated .arb and .dart files for localization in Flutter. It is generated under the directory .dart_tool/flutter_gen/

When using Quick Fix to find AppLocalizations.of(context) it doesn't suggest the import that should be like following: import 'package:flutter_gen/gen_l10n/app_localizations.dart';

This import is needed for basically every file in the UI that displays text, so it would help a lot if it was possible to get suggested imports from custom directories outside lib/ as well.

What is the fix

Please make a way to customize the directory scope of the import suggestions or make it automatically somehow.

Other information

For now, I am handling this by making another file within the project with the following code: AppLocalizations l10nOf(BuildContext context) => AppLocalizations.of(context);

scheglov commented 2 years ago

What is the mechanism that adds flutter_gen to a package? Is .dart_tool/package_config.json somehow updated? Is there any signal in pubspec.yaml that will say that this package requires such package:flutter_gen generation?

asashour commented 2 years ago

As specified in Flutter internationalization, there are two things in pubspec.yaml:

dependencies:
  flutter_localizations:
    sdk: flutter    # this

flutter:
  generate: true    # and this
DanTup commented 2 years ago

There's an open issue at https://github.com/flutter/flutter/issues/102983 about re-thinking how flutter_gen works because it causes quite a few problems (for ex. this also came up at https://github.com/Dart-Code/Dart-Code/issues/3948).