You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AppLocalizations class from flutter_gen does not show in completion/have import fix #3948
Describe the bug
When using flutter_localizations, the extension doesn't lint/track AppLocalizations nor its import 'package:flutter_gen/gen_l10n/app_localizations.dart' automatically.
To Reproduce
Steps to reproduce the behavior:
Install and setup flutter_localizations
Go in any dart file and try to type AppLocalizations: no Quick Fix available, and we have to import the package manually.
Expected behavior
It should suggest import 'package:flutter_gen/gen_l10n/app_localizations.dart' in the Quick Fixes dropdown list.
Screenshots
Please complete the following information:
Operating System and version: Windows 10.0.19044.1645
VS Code version: 1.66.2
Dart extension version: 3.40.0
Dart/Flutter SDK version: Channel stable, 2.10.4
Target device (if the issue relates to Flutter debugging): None
changed the title [-]Missing lint for flutter_localizations[/-][+]AppLocalizations class from flutter_gen does not show in completion/have import fix[/+]on May 3, 2022
@bwilkerson it seems the reason for this is that the flutter_gen package is not explicitly listed in pubspec.yaml, so the server doesn't suggest it for any import fixes (or its paths when typing an import 'package: import).
The flutter_gen package is injected only into .dart_tool/package_config.json during flutter pub get, but it is intended to be referenced directly by user code (see here).
If I manually add flutter_gen to my pubspec (after letting Flutter create it and add it to .dart_tool/package_config.json) then the quick-fix shows up (although, I still don't get completion for paths on the import):
I'm not sure what a good fix for this is. Flutter injecting flutter_gen into .dart_tool/package_config.json without it being in pubspec has always seemed slightly odd and a change to the Linter's depend_on_referenced_packages lint was described as "a hack" in dart-lang/sdk#58690, so I don't know if fixing it as-is in the server would just be adding more debt?
I can confirm this error still exists. I have to manually import import 'package:flutter_gen/gen_l10n/app_localizations.dart' to access AppLocalizations in the app.
Also it's very strange it's been one year and this didn't get fixed.
This issue is blocked on flutter/flutter#102983. The way Flutter currently generates this package means it's not listed in pubspec.yaml and the analysis server will only suggest things that are direct dependencies.
This resolves this problem because they won't be in a package that's injected only into package_config.json, but instead will live inside your project like any other code.
Activity
[-]Missing lint for flutter_localizations[/-][+]AppLocalizations class from flutter_gen does not show in completion/have import fix[/+]DanTup commentedon May 3, 2022
@bwilkerson it seems the reason for this is that the
flutter_genpackage is not explicitly listed inpubspec.yaml, so the server doesn't suggest it for any import fixes (or its paths when typing animport 'package:import).The
flutter_genpackage is injected only into.dart_tool/package_config.jsonduringflutter pub get, but it is intended to be referenced directly by user code (see here).If I manually add
flutter_gento my pubspec (after letting Flutter create it and add it to.dart_tool/package_config.json) then the quick-fix shows up (although, I still don't get completion for paths on theimport):I'm not sure what a good fix for this is. Flutter injecting
flutter_geninto.dart_tool/package_config.jsonwithout it being inpubspechas always seemed slightly odd and a change to the Linter'sdepend_on_referenced_packageslint was described as "a hack" in dart-lang/sdk#58690, so I don't know if fixing it as-is in the server would just be adding more debt?axiftaj commentedon Jun 14, 2023
I can confirm this error still exists. I have to manually import import 'package:flutter_gen/gen_l10n/app_localizations.dart' to access AppLocalizations in the app.
Also it's very strange it's been one year and this didn't get fixed.
DanTup commentedon Jun 14, 2023
This issue is blocked on flutter/flutter#102983. The way Flutter currently generates this package means it's not listed in
pubspec.yamland the analysis server will only suggest things that are direct dependencies.intl docs: Remove instruction to import bindings file
ps6067966 commentedon Jan 16, 2025
Still facing this issue.
DanTup commentedon Feb 24, 2025
There's an upcoming change to Flutter so that localized messages live inside the application source (and not a synthetic package), see:
package:flutter_genflutter/flutter#102983--explicit-package-dependenciesby default. flutter/flutter#160289This resolves this problem because they won't be in a package that's injected only into
package_config.json, but instead will live inside your project like any other code.sallytimmer commentedon May 11, 2025
The solution is to set this command in the project root terminal:
flutter config --no-explicit-package-dependencies
That will undo this settings:
flutter config --explicit-package-dependencies