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

9

13

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?

Merla answered 1/6, 2021 at 13:31 Comment(1)
H
22

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://mcmap.net/q/233699/-target-of-uri-doesn-39-t-exist-39-package-flutter_gen-gen_l10n-gallery_localizations-dart-39 and https://mcmap.net/q/233699/-target-of-uri-doesn-39-t-exist-39-package-flutter_gen-gen_l10n-gallery_localizations-dart-39.

Henden answered 11/9, 2021 at 13:33 Comment(1)
Dart: Restart Analysis Server. It works! thanksAnthropometry
H
7

Just type in the project terminal flutter gen-l10n it will solve your problem.

Hypnotherapy answered 3/1, 2023 at 6:40 Comment(1)
This works on my case. I'm using VSCode.Schmaltz
W
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'

Wigging answered 28/4, 2022 at 1:48 Comment(1)
Thanks @giorgio79. That was the issue for me. In my case, I added flutter_gen package to the dependencies instead of adding flutter_gen_runner to dev_dependencies.Culex
C
4

Open Command Palette and select Dart: Restart Analysis Server.

enter image description here

Cleanser answered 15/2, 2022 at 15:37 Comment(0)
U
2

Also, in the pubspec.yaml file, enable the generate flag. This is added to the section of the pubspec that is specific to Flutter, and usually comes later in the pubspec file.

# The following section is specific to Flutter.
flutter:
  generate: true # Add this line
Unswerving answered 3/1, 2023 at 6:19 Comment(0)
F
0

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.

Freestanding answered 5/11, 2021 at 0:48 Comment(0)
G
0

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

Glossographer answered 7/2, 2022 at 21:36 Comment(0)
R
0

You can restart Dart Analysis Server and the issue will be resolved.

If you use VS Code:

View -> Command Palette -> select Dart: Restart Analysis Server.

If you use Android studio:

enter image description here

Romanism answered 10/7 at 12:24 Comment(0)
S
-2

Just in your terminal run this command:

flutter pub add flutter_gen/gen_l10n

It fixed my app

Silverman answered 4/10, 2021 at 18:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.