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

Viewed 3890

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?

6 Answers

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.

Open Command Palette and select Dart: Restart Analysis Server.

enter image description here

just in Your terminal run this

flutter pup add flutter_gen/gen_l10n

It fixed my app

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.

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

Related