Flutter 国际化
1.在Plugins中加入Flutter Intl插件
2.添加依赖
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
3.初始化Intl
Tools->Flutter Intl-> Initialize for the Project
执行完后会在lib目录下生成generated和l10n两个目录
4.添加语言
Tools->Flutter Intl-> Add locale
执行完后,会在generated和l10n两个目录中加入对应文件
5.配置多语言
在MaterialApp中配置supportedLocales和localizationsDelegates
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
//设置支持的多语言组
supportedLocales: S.delegate.supportedLocales,
//多语言 委托
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidg