[英]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我已阅读这篇文章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:如果您使用 X lang,我会尝试确定是否会显示其他 class:
if(_getLanguageCode(context) !='en') return Myclass() if(_getLanguageCode(context) !='en') return Myclass()
this my getlanguagecode:这是我的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.如果您只想在语言代码不同于“en”时显示页面,您可以定义一个 MaterialPageRoute 并通过 Navigator.push 推送它。
if (_getLanguageCode(context) != 'en')
Navigator.push(context,
MaterialPageRoute(builder: (context) => YourClass()));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.