简体   繁体   中英

How can i use if statment with flutter locale to show class

i have read this article https://medium.com/saugo360/managing-locale-in-flutter-7693a9d4d6ac

and i try to make if that will show other class if you use X lang for example:

if(_getLanguageCode(context) !='en') return Myclass()

this my getlanguagecode:

_getLanguageCode(BuildContext context) {
  return Localizations.localeOf(context).languageCode;
}

hope can help me with this.

If you want to show a page only if the language code is different than 'en' you can define a MaterialPageRoute and push it via Navigator.push.

if (_getLanguageCode(context) != 'en') 
            Navigator.push(context,
                MaterialPageRoute(builder: (context) => YourClass()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM