配置环境
- VSCode,安装 Flutter Intf 插件

- 打开工程,初始化模块

初始化后,会在lib目录中看到
1 2 3 4 5 6
| lib - generated - intl - l10n.dart - l10n - intl_en.arb
|
根据需要,通过 >Flutter Intl: Add locale 添加需要支持的语言

添加后,会在 l10n 目录下看到 intl_xx_xx.arb 的资源文件,需要使用的文案往里面添加即可。
使用资源
在初始化MaterialApp的代码中,添加国际化的支持
1 2 3 4 5 6 7 8 9 10 11
| return MaterialApp( localizationsDelegates: const [ S.delegate, GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate, GlobalWidgetsLocalizations.delegate, ], supportedLocales: S.delegate.supportedLocales, locale: model.locale, home: const MyHomePage(), );
|
在后面的Widget中,可以通过context来获取对应的文案