2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

error: Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'.を解消する

Posted at

エラー全文

error: Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'.

とか

error: Undefined name 'AppLocalizations'.

とかのエラーが、Flutter3.32系から発生するようになりました

原因

Flutter 3.32.0以降、国際化(i18n)に関する重要な変更が導入され、
flutter gen-l10nコマンドの挙動が変更され、従来のpackage:flutter_genの使用が非推奨となったため

移行手順

移行の対象か確認

以下のようにgenerate: trueとしているプロジェクト

pubspec.yaml
flutter:
  generate: true

手順1

l10n.yaml に synthetic-package: false を追加

+ synthetic-package: false 
arb-dir: lib/i18n # .arbファイルが配置されていたディレクトリを指定 自分は`lib/localization`でした
- output-localization-file: app_localizations.dart
+ output-dir: lib/generated/i18n # 新規でapp_localizations.dart等が格納されるディレクトリを指定

手順2

app_localizationsを作成する

flutter pub get

手順1で設定したoutput-dirlib/generated/i18n/app_localizations.dart
lib/generated/i18n/app_localizations_ja.dartが作成される

手順3

インポートパスの修正

+ import 'package:your_app_name/generated/i18n/app_localizations.dart';
- import 'package:flutter_gen/gen_l10n/app_localizations.dart';

手順3

flutter configコマンドの使用(オプション)
明示的なパッケージ依存関係の管理を有効化する

flutter config --explicit-package-dependencies

参考

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?