添加依赖
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
按照教程安装好插件后: 打开cmd+shift+p
1.Flutter I18n Json: Initialize, 初始化后会创建以下文件
i18n/<default-locale>.json
lib/generated/i18n.dart
i18nconfig.json
2.Flutter I18n Json: Add locale, 添加要支持的语言,例如 输入 zh-CN

4.使用:除了按照官方教程添加代码外,格外注意,需要在设置localizationsDelegates的地方,额外添加
localizationsDelegates: [i18n,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate],
避免使用有问题,我自己使用时刚开始没添加下面三个,fultter报错了, 如图

5.iOS使用还需要在Runner工程的info.plist添加
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>es</string>
<string>ru</string>
</array>
,以及如图所示

网友评论