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 ?
CodePudding user response:
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
CodePudding user response:
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
);
CodePudding user response:
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;