VSCode cannot Autoimport flutter_gen

Viewed 651

I'm following this doc to implement localization in my app. I run flutter build apk and it generates related localization classes. However, when I want to import AppLocalizations under lib, it does not automatically import it. So I manually write import 'package:flutter_gen/gen_l10n/app_localizations.dart'; to every file I'd like to use localization.

I was wondering if there's a way to make VSCode autoimport generated AppLocalizations class when I do CTRL+. since writing import each time is a pain.

l10n.yaml file

arb-dir: l10n
template-arb-file: app_tr.arb
output-localization-file: app_localizations.dart

Environment

1 Answers

I had the same problem. I have taken another way to localize my Flutter app. In Visual Studio Code, I have installed this plugin, Flutter Intl (localizely.flutter-intl) and I have followed the plugin instructions. In this scenario, the LocalizationDelegate file, is built inside /lib folder.

In this way, the auto-import works fine. Futhermore with this plugin, I can use ICU format messages like select, plural, etc in easy way.

Related