Skip to content

Commit

Permalink
fix: openfoodfacts#1673 - force preferences refresh when we changed l…
Browse files Browse the repository at this point in the history
…anguages

Impacted file:
* `product_preferences.dart`
  • Loading branch information
monsieurtanuki committed May 5, 2022
1 parent 21253c1 commit cee21cf
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/smooth_app/lib/data_models/product_preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,25 @@ class ProductPreferences extends ProductPreferencesManager with ChangeNotifier {
/// The downloaded strings are automatically stored in the database.
Future<bool> _loadFromNetwork(String languageCode) async {
try {
final bool differentLanguages;
if (daoString != null) {
final String? latestLanguage =
await daoString!.get(_DAO_STRING_KEY_LANGUAGE);
differentLanguages = latestLanguage != languageCode;
} else {
differentLanguages = true;
}
final String importanceUrl =
AvailablePreferenceImportances.getUrl(languageCode);
final String attributeGroupUrl =
AvailableAttributeGroups.getUrl(languageCode);
final DownloadableString downloadableImportance;
downloadableImportance =
final DownloadableString downloadableImportance =
DownloadableString(Uri.parse(importanceUrl), dao: daoString);
final bool differentImportance = await downloadableImportance.download();
final DownloadableString downloadableAttributes =
DownloadableString(Uri.parse(attributeGroupUrl), dao: daoString);
final bool differentAttributes = await downloadableAttributes.download();
// the downloaded values are identical to what was stored locally.
if ((!differentImportance) && (!differentAttributes)) {
if (!(differentImportance || differentAttributes || differentLanguages)) {
return false;
}
final String preferenceImportancesString = downloadableImportance.value!;
Expand Down

0 comments on commit cee21cf

Please sign in to comment.