(1) yaml文件添加依賴
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
(2) 安裝Flutter Intl引擎

飛書20211231-184240.png
(3) 執(zhí)行命令,生成國際化初始化代碼

截屏2021-12-31 下午6.42.26.png
(4) 查看生成的文件,編輯arb文件
i10n.dart文件中生成S類
intl_en.arb對應英文的json文件
intl_zh.arb對應中文的json文件

截屏2021-12-31 下午6.52.00.png

截屏2021-12-31 下午6.46.05.png
(5) MaterialApp中進行配置
MaterialApp(
supportedLocales: S.delegate.supportedLocales,
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
S.delegate,
],
);
(5) 不同界面中獲取國際化配置的內容
S.of(context).bottomBarTitle1;
S.of(context).bottomBarTitle2;
S.of(context).bottomBarTitle3;