I’m trying to generate localization files in my Flutter project using flutter gen-l10n, but it doesn’t seem to work. I keep getting the error after running flutter gen-l10n:
Attempted to generate localizations code without having the flutter: generate flag turned on.
Check pubspec.yaml and ensure that flutter: generate: true has been added and rebuild the project. Otherwise, the localizations source code will not be importable.
My pubspec.yaml looks like this:
name: Test
description: A Flutter project for testing.
publish_to: 'none'
version: 1.0.0+1
environment:
sdk: ">=3.0.0 <4.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.5
shared_preferences: ^2.2.0
google_mobile_ads: ^5.2.0
provider: ^6.0.0
dio: ^5.0.0
flutter_localizations:
sdk: flutter
intl: ^0.19.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.1
flutter:
generate: true
uses-material-design: true
So there is flutter: generate: true in the pubspec
Commands I tried:
flutter clean
rm -rf .dart_tool
flutter pub get
flutter gen-l10n
In lib/l10n/ there are some .arb files (app_en.arb, app_de.arb, app_it.arb, app_es.arb, app_fr.arb)
Does anyone have an idea what could be wrong? Any help is greatly appreciated! Thanks in advance!
I had the same issue. This l10n.yaml resolve this:
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: S.dart
output-class: S
synthetic-package: false
output-dir: lib/generated/l10n
And put nothing under the "flutter:" section in the pubspec.yaml