John Smith Optional
John Smith Optional

Reputation: 24826

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

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?

Upvotes: 0

Views: 835

Answers (1)

10101010
10101010

Reputation: 1821

import 'dart:ui';

....
....

print(window.locale.languageCode);

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

Upvotes: 2

Related Questions