skip to Main Content

I want to change the language of my flutter application by retrieving the default language of the phones set in the preferences. How to do ?

3

Answers


  1. In MaterialApp you can set application language with local property,
    local property by default is system language

    if you don’t set a custom local, app will use system language if this language is available in your app

    Login or Signup to reply.
  2. Yes you can retreive that on the start of the application using localeResolutionCallback in the MaterialApp

    MaterialApp(
                      title: 'SportsTak',
                      home:Home(),
                      localeListResolutionCallback: ( localeOfDevice, listedLocales){
            
                      //Here is what you can loop through listedLocales and compare from localeOfDevice and return the locale you support
                        
                      },
                      supportedLocales:[ ] , //listofsupportedlocales
                    );
    
    Login or Signup to reply.
  3. Yes, you may use Platform.localeName from dart:io to get the name of the current device locale.

    import 'dart:io';
    
    String languageCode = Platform.localeName;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search