问题
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