return MaterialApp(
debugShowCheckedModeBanner: false,
localizationsDelegates: [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
supportedLocales: [
...S.delegate.supportedLocales
],
// ignore: missing_return
localeResolutionCallback: (locale, supportedLocales) {
Util.location = locale.countryCode;
Util.languageCode = locale.languageCode;
if (locale.toString().startsWith('hi')) {
return Locale('hi', 'ID');
}else if(locale.toString().startsWith('zh')){
return Locale('zh', 'CN');
}else{
return Locale('en', 'US');
}
},
navigatorObservers: <NavigatorObserver>[Util.observer],
theme: ThemeData(
primaryColor: Colors.grey[100],
scaffoldBackgroundColor: Colors.grey[100],
backgroundColor: Colors.grey[100]),
home: Splash());
最主要是在这里返回
因为中文的locale 为 zh_Hans_CN
所有 supportedLocales.contains(locale) 判断 return locale 不会成功
localeResolutionCallback: (locale, supportedLocales) {
Util.location = locale.countryCode;
Util.languageCode = locale.languageCode;
if (locale.toString().startsWith('hi')) {
return Locale('hi', 'ID');
}else if(locale.toString().startsWith('zh')){
return Locale('zh', 'CN');
}else{
return Locale('en', 'US');
}
},