1.Android Studio 打开项目 file-setting-plugin 安装flutter intl
2.项目中找到pubspec.xml 添加依赖
flutter_localizations:
sdk: flutter
flutter_cupertino_localizations: ^1.0.1
3.获取项目的依赖包
命令行执行
flutter packages get
4.Android Studio工具栏依次找到tools ---> flutter intl ---> (执行)Inilize for the project,项目中就会生成下列目录
5.main.dart下的MaterialApp模块内新增
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
S.delegate,
],
supportedLocales: S.delegate.supportedLocales,
6.配置多语言
i10n目录下的.arb文件内编辑。类似下图:
7.使用方法
纯文本
示例:
Text(S.of(context).mine)
带变量
示例:
Text(S.of(context).sayHi("Nadia"))
8.效果图
看到的兄弟们,不要忘了点个赞哦