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 application. Applications or tools
that previously referenced package:flutter_gen
will instead reference source
files generated into the application 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 is not
listed in an app's pubspec.yaml
, and is created via re-writing the (generated)
package_config.json
, numerous problems have been created.
Migration Guide
#This change only effects users that have the following in their pubspec.yaml
:
flutter:
generate: true
A synthetic package (package:flutter_gen
) is created and referenced by the
application:
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: false
in the accompanying l10n.yaml file:yamlsynthetic-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/i18n
-
Pass
--no-implicit-pubspec-resolution
to invocations of theflutter
tool:shflutter run --no-implicit-pubspec-resolution
Timeline
#Not released
Not released + 1, package:flutter_gen
support will be removed.
References
#Relevant Issues:
- Issue 73870, where
package:flutter_gen
pub problems are first found. - Issue 102983, where
package:flutter_gen
problems are outlined. - Issue 157819, where
--implicit-pubspec-resolution
is discussed.
Relevant Articles:
- Internationalizing Flutter apps, the canonical documentation for the feature.
除非另有说明,本文档之所提及适用于 Flutter 的最新稳定版本,本页面最后更新时间: 2024-10-31。 查看文档源码 或者 为本页面内容提出建议。