Easy_localization: Error importing package flutter_localizations.

Created on 28 Feb 2020  Â·  10Comments  Â·  Source: aissat/easy_localization

I've been stuck on this issue for several days now after running flutter upgrade I get an error when importing the package flutter_localizations.

Steps to reproduce.

  • Create a new flutter project
  • Add easy_localizations to pubspec dependencies.
  • Try to import flutter_locaizations.

I've tried to run flutter upgrade, flutter packages get, flutter packages pub cache repair and restarting vs code but it did not solve the problem.

flutter doctor -v output

[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Linux, locale en_US.UTF-8)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Android Studio (version 3.6)
[✓] Android Studio (version 3.5)
[!] IntelliJ IDEA Community Edition (version 2019.3)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.42.1)
[!] Connected device
    ! No devices available

! Doctor found issues in 2 categories.

Thanks in advance.

Most helpful comment

@AmmarHazem I just noticed it, you need to include flutter_localizations in your pubspec.yaml.
Add this in your dependencies
flutter_localizations:
sdk: flutter

Take a look here for more information https://flutter.dev/docs/development/accessibility-and-localization/internationalization

All 10 comments

@AmmarHazem could you share the error message or provide an example project?

Yes, Here is the error message
Target of URI doesn't exist: 'package:flutter_localizations/flutter_localizations.dart'. Try creating the file referenced by the URI, or Try using a URI for a file that does exist.dart(uri_does_not_exist)

@AmmarHazem This doesn't seem specific to this package. Does flutter packages get succeed ? or it reports any error. Maybe sharing your pubspec.yaml could help.

The output from flutter packages get
Running "flutter pub get" in raneem... 0.3s

pubspec.yaml
``` name: lost_things
description: A new Flutter project.

version: 1.0.0+1

environment:
sdk: ">=2.2.2 <3.0.0"

dependencies:
flutter:
sdk: flutter

cupertino_icons: ^0.1.2
easy_localization: ^1.3.5
font_awesome_flutter: ^8.5.0
carousel_slider: ^1.4.1
image_picker: ^0.6.3+1
dotted_border: ^1.0.4
auto_animated: ^2.0.1
provider: ^4.0.4
shared_preferences: ^0.5.6+2
dio: ^3.0.8
toast: ^0.1.5

dev_dependencies:
flutter_test:
sdk: flutter

flutter:

uses-material-design: true

assets:

  • assets/images/
  • assets/languages/
  • assets/fonts/

fonts:
- family: MainFont
fonts:
- asset: assets/fonts/JF-Flat-regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
```

@AmmarHazem i don't see an issue right now. Maybe you can also try flutter clean see if that helps, or provide an example project to reproduce the issue.

@AmmarHazem I just noticed it, you need to include flutter_localizations in your pubspec.yaml.
Add this in your dependencies
flutter_localizations:
sdk: flutter

Take a look here for more information https://flutter.dev/docs/development/accessibility-and-localization/internationalization

@spiritinlife Thank you. This solved the problem but shouldn't this be mentioned in the readme of the package ?

@AmmarHazem I am not sure why this package should mention it. It is only relevant if you use

GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,

But maybe a better explanation of this or a proper translation setup should be done moving forward.
@aissat What u think on this ? should we mention it in the docs?

on this ? should we mention it in the docs?

@spiritinlife yep

Was this page helpful?
0 / 5 - 0 ratings

Related issues

enricoquarantini picture enricoquarantini  Â·  4Comments

AdelMahmoudHussein picture AdelMahmoudHussein  Â·  7Comments

Melak12 picture Melak12  Â·  4Comments

VictorCamargo picture VictorCamargo  Â·  6Comments

KarlChow92 picture KarlChow92  Â·  3Comments