From 4b053d8af1c8662a50c8963572f9132a2176f1e0 Mon Sep 17 00:00:00 2001 From: monsieurtanuki Date: Fri, 6 May 2022 12:30:59 +0200 Subject: [PATCH] fix: #1673 - force preferences refresh when we changed languages (#1759) Impacted file: * `product_preferences.dart` --- .../lib/data_models/product_preferences.dart | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/smooth_app/lib/data_models/product_preferences.dart b/packages/smooth_app/lib/data_models/product_preferences.dart index cddfbce3cbe..124dc2390f1 100644 --- a/packages/smooth_app/lib/data_models/product_preferences.dart +++ b/packages/smooth_app/lib/data_models/product_preferences.dart @@ -108,19 +108,25 @@ class ProductPreferences extends ProductPreferencesManager with ChangeNotifier { /// The downloaded strings are automatically stored in the database. Future _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!;