Localized messages are generated into source, not a synthetic package.
Summary
#The flutter tool will no longer generate a synthetic package:flutter_gen or modify the package_config.json of the app.
Applications or tools that referenced package:flutter_gen should instead reference source files generated into the app's source directory directly.
Background
#flutter_gen is a virtual (synthetic) package that is created by the flutter command-line tool to allow developers to import that package to access generated symbols and functionality, such as for internationalization. As the package isn't listed in an app's pubspec.yaml, and is created via re-writing the generated package_config.json file, many problems have been created.
Migration Guide
#This change only affects apps that have the following entry in their pubspec.yaml:
flutter:
generate: trueA synthetic package (package:flutter_gen) is created and referenced by the app:
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
// ...
const MaterialApp(
title: 'Localizations Sample App',
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
);There are two ways to migrate away from importing package:flutter_gen:
Specify
synthetic-package: falsein the accompanyingl10n.yamlfile:l10n.yamlyamlsynthetic-package: false # The files are generated into the path specified by `arb-dir` arb-dir: lib/i18n # Or, specifically provide an output path: output-dir: lib/src/generated/i18nEnable the
explicit-package-dependenciesfeature flag:shflutter config explicit-package-dependencies
Timeline
#Landed in version: Not yet
Stable release: Not yet
One stable release after this change lands, package:flutter_gen support will be removed.
References
#Relevant Issues:
- Issue 73870, where
package:flutter_genpub problems are first found. - Issue 102983, where
package:flutter_genproblems are outlined. - Issue 157819, where
--implicit-pubspec-resolutionis discussed.
Relevant Articles:
- Internationalizing Flutter apps, the canonical documentation for the feature.
除非另有说明,否则本网站上的文档反映的是 Flutter 的最新稳定版本。页面最后更新于 2025-01-30。 查看源代码 或 报告问题。