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

1

0

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?

Rafa answered 11/7, 2019 at 15:6 Comment(0)
E
2
import 'dart:ui';

....
....

print(window.locale.languageCode);

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

Exchequer answered 11/7, 2019 at 15:41 Comment(1)
@JohnSmithOptional this is obviously what you are looking for, I think I read your question too fast. I cannot cancel my downvote unless the answer is edited...Ss

© 2022 - 2024 — McMap. All rights reserved.