From 3260024a561c8e59d5324dd65b995eb574d75be3 Mon Sep 17 00:00:00 2001 From: monsieurtanuki Date: Sun, 27 Oct 2024 16:02:59 +0100 Subject: [PATCH 1/2] fix: 5742 - centered tooltip after detail changes (#5751) Impacted file: * `background_task_details.dart`: centered instead of bottomCentered --- packages/smooth_app/lib/background/background_task_details.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/smooth_app/lib/background/background_task_details.dart b/packages/smooth_app/lib/background/background_task_details.dart index 0431aebc0fa..0e67edd0816 100644 --- a/packages/smooth_app/lib/background/background_task_details.dart +++ b/packages/smooth_app/lib/background/background_task_details.dart @@ -102,7 +102,7 @@ class BackgroundTaskDetails extends BackgroundTaskBarcode final AppLocalizations appLocalizations) => ( appLocalizations.product_task_background_schedule, - AlignmentDirectional.bottomCenter, + AlignmentDirectional.center, ); /// Returns a new background task about changing a product. From 446a8c09d12d4823412446b57fedeb56ebc4af34 Mon Sep 17 00:00:00 2001 From: monsieurtanuki Date: Sun, 27 Oct 2024 16:16:19 +0100 Subject: [PATCH 2/2] feat: 5639 - storing the latest selected product type (#5752) * feat: 5639 - storing the latest selected product type Impacted files: * `search_product_helper.dart`: initialized and set the latest selected product type * `user_preferences.dart`: new preference field where we store the latest selected product type * minor fix --- .../preferences/user_preferences.dart | 17 +++++++++++++++++ .../lib/pages/search/search_product_helper.dart | 11 +++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/smooth_app/lib/data_models/preferences/user_preferences.dart b/packages/smooth_app/lib/data_models/preferences/user_preferences.dart index d2cd3f32d86..fa92405f0f6 100644 --- a/packages/smooth_app/lib/data_models/preferences/user_preferences.dart +++ b/packages/smooth_app/lib/data_models/preferences/user_preferences.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:math' as math; import 'package:flutter/material.dart'; @@ -54,6 +55,9 @@ class UserPreferences extends ChangeNotifier { return _instance!; } + /// Once we initialized with main.dart, we don't need the "async". + static UserPreferences getUserPreferencesSync() => _instance!; + late ValueNotifier onCrashReportingChanged; late ValueNotifier onAnalyticsChanged; @@ -82,6 +86,7 @@ class UserPreferences extends ChangeNotifier { static const String _TAG_USER_GROUP = '_user_group'; static const String _TAG_UNIQUE_RANDOM = '_unique_random'; static const String _TAG_LAZY_COUNT_PREFIX = '_lazy_count_prefix'; + static const String _TAG_LATEST_PRODUCT_TYPE = '_latest_product_type'; /// Camera preferences @@ -468,4 +473,16 @@ class UserPreferences extends ChangeNotifier { ); } } + + ProductType get latestProductType => + ProductType.fromOffTag( + _sharedPreferences.getString(_TAG_LATEST_PRODUCT_TYPE)) ?? + ProductType.food; + + set latestProductType(final ProductType value) => unawaited( + _sharedPreferences.setString( + _TAG_LATEST_PRODUCT_TYPE, + value.offTag, + ), + ); } diff --git a/packages/smooth_app/lib/pages/search/search_product_helper.dart b/packages/smooth_app/lib/pages/search/search_product_helper.dart index 91e0a87ced3..ae4551badaf 100644 --- a/packages/smooth_app/lib/pages/search/search_product_helper.dart +++ b/packages/smooth_app/lib/pages/search/search_product_helper.dart @@ -3,6 +3,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:openfoodfacts/openfoodfacts.dart'; import 'package:provider/provider.dart'; import 'package:smooth_app/data_models/fetched_product.dart'; +import 'package:smooth_app/data_models/preferences/user_preferences.dart'; import 'package:smooth_app/database/dao_string_list.dart'; import 'package:smooth_app/database/local_database.dart'; import 'package:smooth_app/helpers/analytics_helper.dart'; @@ -17,10 +18,11 @@ import 'package:smooth_app/query/product_query.dart'; /// Search helper dedicated to product search. class SearchProductHelper extends SearchHelper { - SearchProductHelper(); + SearchProductHelper() { + _productType = UserPreferences.getUserPreferencesSync().latestProductType; + } - // TODO(monsieurtanuki): maybe reinit it with latest value - ProductType _productType = ProductType.food; + late ProductType _productType; @override String get historyKey => DaoStringList.keySearchProductHistory; @@ -154,7 +156,8 @@ class _ProductTypeFilterState extends State<_ProductTypeFilter> { segments: segments, selected: {widget.searchProductHelper._productType}, onSelectionChanged: (Set newSelection) => setState( - () => widget.searchProductHelper._productType = newSelection.first, + () => UserPreferences.getUserPreferencesSync().latestProductType = + widget.searchProductHelper._productType = newSelection.first, ), ); }