0

I want to set the locale of every showDatePicker in the app, to the locale of the user's location, so that when they click the edit pencil in the DatePicker, they see the initial date in the format of their country.

I have found this to set the system locale:

Intl.systemLocale = await findSystemLocale();

Then when I use showDatePicker I get that locale:

This does not format the date to the users country:

final systemLocale = Intl.systemLocale;
final splittedLocaleChars = systemLocale.split('_');
final locale = Locale(splittedLocaleChars[0], splittedLocaleChars[1]);
final selectedDate = await showDatePicker(
  locale: locale,

And also this inside initState should work:

findSystemLocale().then((value) {
  Intl.systemLocale = value;
  initializeDateFormatting(value, null);
});

But it gives the error:

"Unsupported operation: Cannot modify unmodifiable map"

What am I doing wrong?

BeniaminoBaggins
  • 11,202
  • 41
  • 152
  • 287

0 Answers0