Skip to content

AppLocalizations class from flutter_gen does not show in completion/have import fix #3948

Closed

Description

@TiffApps

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:

  1. Install and setup flutter_localizations
  2. 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
image

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

Activity

  1. 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
  2. added
    in flutterRelates to running Flutter apps
    in lsp/analysis serverSomething to be fixed in the Dart analysis server
    on May 3, 2022
  3. DanTup commented on May 3, 2022

    @DanTup
    Member

    @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):

    Screenshot 2022-05-03 at 16 00 32

    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?

  4. added this to the Backlog milestone on May 23, 2022
  5. axiftaj commented on Jun 14, 2023

    @axiftaj

    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.

  6. DanTup commented on Jun 14, 2023

    @DanTup
    Member

    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.

  7. ps6067966 commented on Jan 16, 2025

    @ps6067966

    Still facing this issue.

  8. DanTup commented on Feb 24, 2025

    @DanTup
    Member

    There's an upcoming change to Flutter so that localized messages live inside the application source (and not a synthetic package), see:

    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.

  9. added
    relies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available
    and removed on Feb 24, 2025
  10. modified the milestones: Backlog, v3.108.0 on Feb 24, 2025
  11. sallytimmer commented on May 11, 2025

    @sallytimmer

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in dart / flutterin flutterRelates to running Flutter appsin lsp/analysis serverSomething to be fixed in the Dart analysis serveris bugrelies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions