useDeviceLocale method
Use the device's locale if supported, otherwise default to configured default
Implementation
Future<void> useDeviceLocale() async {
final deviceLocale = WidgetsBinding.instance.platformDispatcher.locale;
if (_isLocaleSupported(deviceLocale)) {
await setLocale(deviceLocale);
} else {
// Try to match language code only (ignore country code)
final languageLocale = Locale(deviceLocale.languageCode);
if (_isLocaleSupported(languageLocale)) {
await setLocale(languageLocale);
} else {
// Default to configured default locale
await setLocale(defaultLocale.locale);
}
}
}