'Error setting-up flutter_localizations package "Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'."

This error appears when I try to add language support to my flutter application:

Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'. Try creating the file referenced by the URI, or Try using a URI for a file that does exist.

I’m using flutter_localizations, the project is built with dart 2.7.0

It seems that flutter_localizations needs latest sdk which is dart 2.13.0

How can I fix this?



Solution 1:[1]

I had this same issue with import 'package:flutter_gen/gen_l10n/app_localizations.dart' in Visual Studio Code after updating to Flutter 2.5.

After closing the VS Code window and reopening it, the error was gone. If that doesn't work, try closing and opening VS Code again.

Or restart the Dart Analysis Server by going to View > Command Palette and then typing Dart: Restart Analysis Server.

Credit goes to https://stackoverflow.com/a/68150402/4797855 and https://stackoverflow.com/a/68731436/4797855.

Solution 2:[2]

Open Command Palette and select Dart: Restart Analysis Server.

enter image description here

Solution 3:[3]

just in Your terminal run this

flutter pup add flutter_gen/gen_l10n

It fixed my app

Solution 4:[4]

I had this issue before, and I tried to solve it by adding charts_flutter to my pubspec.yaml but it didn't solve my.

Lucky me, charting library recently released a new version which is compatible with flutter 2.5. I didn't need to add anything to my pubspec(I removed chart_flutter from my ). just run the app even if the compiler shows an error saying Target of URI doesn't exist for the import line. The system is going to generate that file on runtime.

Solution 5:[5]

Be sure that there's an l10n.yaml file in your project root as follows.

Example

Demonstration variables

foldername = l10n
defaultIntlFile = intl_en.arb
importFileName = app_localizations.dart

Import

import 'package:flutter_gen/gen_l10n/importFileName';

l10n.yaml

arb-dir: lib/foldername
template-arb-file: intl_en.arb
output-localization-file: app_localizations.dart

Structure

lib/foldername/defaultIntlFile

Solution 6:[6]

The solution in my case: "If you are using a package flutter_gen you need to remove it from pubscpec.yaml to resolve conflict." credit Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/gallery_localizations.dart'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Abir Ahsan
Solution 3 Ineza
Solution 4 Dharman
Solution 5 Tobias Krainhöfner
Solution 6 giorgio79