0 purchases
comm app
flutter app encapsulates basic app functions #
1、LanguageUtils language switching function #
1、Initialize language list
void main() async {
/// Initialize utils
await XUtils.get.init(debug: kDebugMode);
///SpUtils is used, so you need to initialize xutils first
var languageList = <LanguageVo>[];
languageList.add(LanguageVo(Language.en.name, Language.en.languageCode, Language.en.countryCode));
languageList.add(LanguageVo(Language.cn.name, Language.cn.languageCode, Language.cn.countryCode));
languageList.add(LanguageVo(Language.tw.name, Language.tw.languageCode, Language.tw.countryCode));
LanguageUtils.get.init(languageList, (locale) => S.load(locale));
runApp(const MyApp());
}
2、Internationalization: configure the current language
GetMaterialApp(
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
locale: LanguageUtils.get.getCurrentLocal(),
supportedLocales: S.delegate.supportedLocales,
...
);
3、switch language
LanguageUtils.get.changeLanguage(value, (locale) => S.load(locale));
///Re render page
setState(() {});
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.