Closed kightsonsanom closed 4 years ago
Hi @kightsonsanom, this is not actually a bug with the plugin itself but rather from iOS simulator that you might be using with it.
For some reason, iOS simulators don't have a default country set (this doesn't ever happen with real devices btw) and you'll need to go to settings > general > language & region > region > select one, even if it's already selected. After that you should be fine.
Anyway, I've updated the assert
to also make sure that countryCode
is not null
and provide this same information to the developer as it may be missed at first.
Let me know if it worked for you.
Thanks!
Hi @miguelpruivo thank you for the quick answer.
The issue above happened to me on an Android emulator but I also checked on physical Pixel 2 XL and OnePlus 6 and it also happens there. For some reason, countryCode
is still null.
What about accessing CountryDetails map keys by languageCode
instead? This property is a required one on Locale object.
@kightsonsanom I'm afraid that every device should have a country associated because the language tag must be from a country. This is, en
can be a language tag from many countries, and this could result in wrong information being provided. How could one tell if en
is from US or GB, for example?
I'm surprised that in Android devices you are experiencing this. Might have to investigate this. At first, this was only an issue with iOS simulators.
I agree that the country code is necessary for this case. If you find yourself not able to reproduce the issue I can provide more details. Thanks!
@kightsonsanom yes, that would be great. How do you manage to replicate it consistently?
I am actually doing it the same way it is done in the package README :
Initialize the plugin:
Use it on the first screen of the application. I use it in didChangeDependencies
not initState
because of Localizations
Inherited widget, but in the build
method the result is the same.
Here I think there is a mistake in plugin Readme, detailsForLocale
is a method defined in CountryCodes
not CountryDetails
class but its not that important. Also in Readme, there is Localization
instead if Localizations
, is that a typo too? Also Readme fragment for the reference.
For some reason, iOS simulators don't have a default country set (this doesn't ever happen with real devices btw) and you'll need to go to settings > general > language & region > region > select one, even if it's already selected. After that you should be fine.
@miguelpruivo I was able to reproduce this one as well. It happens on iOS simulator when we request device-specific locale like this
final localeCodes = CountryCodes.detailsForLocale();
In such case setting region in the settings solves this particular problem but it is different than than the issue of this topic.
Added default Locale
to en-US
on 1.0.1 whenever device hasn't one — although this is likely to only happen on iOS simulators.
Hello,
I am trying to get country code based on the locale of the application, here is how I am invoking the method:
Following throws this error:
This is caused because
countryCode
is an optional parameter in Locale and might be null, here is the locale constructor:and here is how the locale is resolved in the library