initCountry static method
- UserPreferences userPreferences
Sets the global country for API queries: implicit choice at init time.
Implementation
static Future<void> initCountry(UserPreferences userPreferences) async {
// not ideal, but we have many contributors monitoring France
const OpenFoodFactsCountry defaultCountry = OpenFoodFactsCountry.FRANCE;
final String? isoCode =
userPreferences.userCountryCode ??
PlatformDispatcher.instance.locale.countryCode?.toLowerCase();
final OpenFoodFactsCountry country =
OpenFoodFactsCountry.fromOffTag(isoCode) ?? defaultCountry;
await _setCountry(userPreferences, country);
if (userPreferences.userCurrencyCode == null) {
// very very first time, or old app with new code
final Currency? possibleCurrency = country.currency;
if (possibleCurrency != null) {
await userPreferences.setUserCurrencyCode(possibleCurrency.name);
}
}
}