How to get the preferred language of a user before building a widget in Flutter?

╄→гoц情女王★ 提交于 2020-02-03 01:51:08

问题


I'd like to know what is the preferred language of the user (on Android that's something that the user defines in the Android's settings). I'd like to get this value. For example "fr", "en", "ja", or maybe "fr-CA", "en-US", "ja-JP".

I just want to get the user preferred language to build a small widget within the app in the language the user prefers. This is something that should be very simple but I couldn't find a way to do this.

For example, on Android, in Java, you can do

Locale.getDefault().getLanguage() 

And that gives you the preferred language of the user. What is the equivalent in Flutter?


回答1:


import 'dart:ui';

....
....

print(window.locale.languageCode);

If english it will output en, if german de etc.



来源:https://stackoverflow.com/questions/56992283/how-to-get-the-preferred-language-of-a-user-before-building-a-widget-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!