If you develop an application, you may need to detect what is the language or locale used by the device. Especially if the application supports multi-

Flutter - Get Device Language (Locale) Examples

submited by
Style Pass
2025-01-19 16:00:03

If you develop an application, you may need to detect what is the language or locale used by the device. Especially if the application supports multi-language. By doing so, the application can automatically use the most suitable locale according to the device. This tutorial includes how to enable localization in a Flutter application, how to get the language code and locale code, as well as how to detect locale change.

Flutter has a Locale class by which you can get the country code and language code (such as en-US, en-UK, es-ES). It's possible to get the current locale from the BuildContext. However, a Flutter application only supports English (United States) (en-US) locale by default. Therefore, even if the device uses another language, if the device language is not supported by the Flutter application, you'll get the default locale which is en-US.

As a result, you need to make the Flutter application supports localization and set the list of allowed locales. First of all, add flutter_localizations to the pubspec.yaml file, right under the dependencies key.

Leave a Comment