多语言基本实现
导入国际化插件:在根目录pubspec.yaml
导入
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
让app支持语言
runApp(MaterialApp(
routes: {
Routes.page2: (context) => const LocalizationPage1(),
Routes.page1: (context) => const LocalizationPage(),
},
initialRoute: Routes.page1,
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
ZhCNLocaleDelegate()
],
supportedLocales: LocalesCode.locales,
localeListResolutionCallback:
(List<Locale>? locales, Iterable<Locale> supportedLocales) {
print('localeListResolutionCallback语言列表=$locales');
<