From e90da5033fc81fb2cdf4eb4d47865fa558d63d62 Mon Sep 17 00:00:00 2001 From: Valimp Date: Fri, 22 Nov 2024 15:02:45 +0100 Subject: [PATCH] fix: merge ProductType extensions on a single file --- .../lib/pages/offline_data_page.dart | 2 +- .../add_new_product/add_new_product_page.dart | 3 +- ...dart => product_type_radio_list_tile.dart} | 34 +-------- .../product/product_incomplete_card.dart | 2 +- .../product_page/new_product_footer.dart | 1 + .../product/product_type_extensions.dart | 75 +++++++++++++++++++ .../pages/search/search_product_helper.dart | 2 +- .../smooth_app/lib/query/product_query.dart | 48 +----------- 8 files changed, 85 insertions(+), 82 deletions(-) rename packages/smooth_app/lib/pages/product/add_new_product/{add_new_product_type.dart => product_type_radio_list_tile.dart} (83%) create mode 100644 packages/smooth_app/lib/pages/product/product_type_extensions.dart diff --git a/packages/smooth_app/lib/pages/offline_data_page.dart b/packages/smooth_app/lib/pages/offline_data_page.dart index 382e502fbd5..18c648aefed 100644 --- a/packages/smooth_app/lib/pages/offline_data_page.dart +++ b/packages/smooth_app/lib/pages/offline_data_page.dart @@ -11,7 +11,7 @@ import 'package:smooth_app/database/local_database.dart'; import 'package:smooth_app/generic_lib/design_constants.dart'; import 'package:smooth_app/generic_lib/duration_constants.dart'; import 'package:smooth_app/helpers/app_helper.dart'; -import 'package:smooth_app/query/product_query.dart'; +import 'package:smooth_app/pages/product/product_type_extensions.dart'; import 'package:smooth_app/widgets/smooth_app_bar.dart'; import 'package:smooth_app/widgets/smooth_scaffold.dart'; diff --git a/packages/smooth_app/lib/pages/product/add_new_product/add_new_product_page.dart b/packages/smooth_app/lib/pages/product/add_new_product/add_new_product_page.dart index fc07acaf806..25ccaa47ccb 100644 --- a/packages/smooth_app/lib/pages/product/add_new_product/add_new_product_page.dart +++ b/packages/smooth_app/lib/pages/product/add_new_product/add_new_product_page.dart @@ -19,12 +19,13 @@ import 'package:smooth_app/helpers/product_cards_helper.dart'; import 'package:smooth_app/pages/crop_parameters.dart'; import 'package:smooth_app/pages/image_crop_page.dart'; import 'package:smooth_app/pages/preferences/user_preferences_widgets.dart'; -import 'package:smooth_app/pages/product/add_new_product/add_new_product_type.dart'; +import 'package:smooth_app/pages/product/add_new_product/product_type_radio_list_tile.dart'; import 'package:smooth_app/pages/product/add_new_product_helper.dart'; import 'package:smooth_app/pages/product/common/product_dialog_helper.dart'; import 'package:smooth_app/pages/product/nutrition_page_loaded.dart'; import 'package:smooth_app/pages/product/product_field_editor.dart'; import 'package:smooth_app/pages/product/product_image_swipeable_view.dart'; +import 'package:smooth_app/pages/product/product_type_extensions.dart'; import 'package:smooth_app/pages/product/simple_input_page_helpers.dart'; import 'package:smooth_app/query/product_query.dart'; import 'package:smooth_app/widgets/smooth_scaffold.dart'; diff --git a/packages/smooth_app/lib/pages/product/add_new_product/add_new_product_type.dart b/packages/smooth_app/lib/pages/product/add_new_product/product_type_radio_list_tile.dart similarity index 83% rename from packages/smooth_app/lib/pages/product/add_new_product/add_new_product_type.dart rename to packages/smooth_app/lib/pages/product/add_new_product/product_type_radio_list_tile.dart index 8b47b1f8d0a..aa373190cea 100644 --- a/packages/smooth_app/lib/pages/product/add_new_product/add_new_product_type.dart +++ b/packages/smooth_app/lib/pages/product/add_new_product/product_type_radio_list_tile.dart @@ -3,6 +3,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:openfoodfacts/openfoodfacts.dart'; import 'package:smooth_app/generic_lib/design_constants.dart'; +import 'package:smooth_app/pages/product/product_type_extensions.dart'; import 'package:smooth_app/resources/app_icons.dart' as icons; import 'package:smooth_app/themes/smooth_theme_colors.dart'; import 'package:smooth_app/themes/theme_provider.dart'; @@ -20,10 +21,10 @@ class ProductTypeRadioListTile extends StatefulWidget { final void Function(ProductType) onChanged; @override - State createState() => _AddNewProductType(); + State createState() => _ProductTypeRadioListTile(); } -class _AddNewProductType extends State +class _ProductTypeRadioListTile extends State with TickerProviderStateMixin { AnimationController? _controller; late Animation _colorAnimation; @@ -195,32 +196,3 @@ class _AddNewProductType extends State ); } } - -extension ProductTypeExtension on ProductType { - String getTitle(AppLocalizations appLocalizations) { - return switch (this) { - ProductType.food => appLocalizations.product_type_label_food, - ProductType.beauty => appLocalizations.product_type_label_beauty, - ProductType.petFood => appLocalizations.product_type_label_pet_food, - ProductType.product => appLocalizations.product_type_label_product, - }; - } - - String getSubtitle(AppLocalizations appLocalizations) { - return switch (this) { - ProductType.food => appLocalizations.product_type_subtitle_food, - ProductType.beauty => appLocalizations.product_type_subtitle_beauty, - ProductType.petFood => appLocalizations.product_type_subtitle_pet_food, - ProductType.product => appLocalizations.product_type_subtitle_product, - }; - } - - String getIllustration() { - return switch (this) { - ProductType.food => 'assets/misc/logo_off_half.svg', - ProductType.beauty => 'assets/misc/logo_obf_half.svg', - ProductType.petFood => 'assets/misc/logo_opff_half.svg', - ProductType.product => 'assets/misc/logo_opf_half.svg', - }; - } -} diff --git a/packages/smooth_app/lib/pages/product/product_incomplete_card.dart b/packages/smooth_app/lib/pages/product/product_incomplete_card.dart index 6b81cc0e1ef..0dad587f222 100644 --- a/packages/smooth_app/lib/pages/product/product_incomplete_card.dart +++ b/packages/smooth_app/lib/pages/product/product_incomplete_card.dart @@ -5,8 +5,8 @@ import 'package:smooth_app/generic_lib/design_constants.dart'; import 'package:smooth_app/helpers/analytics_helper.dart'; import 'package:smooth_app/pages/product/add_new_product/add_new_product_page.dart'; import 'package:smooth_app/pages/product/product_field_editor.dart'; +import 'package:smooth_app/pages/product/product_type_extensions.dart'; import 'package:smooth_app/pages/product/simple_input_page_helpers.dart'; -import 'package:smooth_app/query/product_query.dart'; /// "Incomplete product!" card to be displayed in product summary, if relevant. /// diff --git a/packages/smooth_app/lib/pages/product/product_page/new_product_footer.dart b/packages/smooth_app/lib/pages/product/product_page/new_product_footer.dart index 2e55bcac574..e8411636446 100644 --- a/packages/smooth_app/lib/pages/product/product_page/new_product_footer.dart +++ b/packages/smooth_app/lib/pages/product/product_page/new_product_footer.dart @@ -18,6 +18,7 @@ import 'package:smooth_app/pages/product/common/product_query_page_helper.dart'; import 'package:smooth_app/pages/product/edit_product_page.dart'; import 'package:smooth_app/pages/product/product_list_helper.dart'; import 'package:smooth_app/pages/product/product_page/new_product_page.dart'; +import 'package:smooth_app/pages/product/product_type_extensions.dart'; import 'package:smooth_app/query/category_product_query.dart'; import 'package:smooth_app/query/product_query.dart'; import 'package:smooth_app/resources/app_icons.dart' as icons; diff --git a/packages/smooth_app/lib/pages/product/product_type_extensions.dart b/packages/smooth_app/lib/pages/product/product_type_extensions.dart new file mode 100644 index 00000000000..43cf39defcc --- /dev/null +++ b/packages/smooth_app/lib/pages/product/product_type_extensions.dart @@ -0,0 +1,75 @@ +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:openfoodfacts/openfoodfacts.dart'; + +extension ProductTypeExtension on ProductType { + String getTitle(AppLocalizations appLocalizations) { + return switch (this) { + ProductType.food => appLocalizations.product_type_label_food, + ProductType.beauty => appLocalizations.product_type_label_beauty, + ProductType.petFood => appLocalizations.product_type_label_pet_food, + ProductType.product => appLocalizations.product_type_label_product, + }; + } + + String getSubtitle(AppLocalizations appLocalizations) { + return switch (this) { + ProductType.food => appLocalizations.product_type_subtitle_food, + ProductType.beauty => appLocalizations.product_type_subtitle_beauty, + ProductType.petFood => appLocalizations.product_type_subtitle_pet_food, + ProductType.product => appLocalizations.product_type_subtitle_product, + }; + } + + String getIllustration() { + return switch (this) { + ProductType.food => 'assets/misc/logo_off_half.svg', + ProductType.beauty => 'assets/misc/logo_obf_half.svg', + ProductType.petFood => 'assets/misc/logo_opff_half.svg', + ProductType.product => 'assets/misc/logo_opf_half.svg', + }; + } + + String getDomain() => switch (this) { + ProductType.food => 'openfoodfacts', + ProductType.beauty => 'openbeautyfacts', + ProductType.petFood => 'openpetfoodfacts', + ProductType.product => 'openproductsfacts', + }; + + String getLabel(final AppLocalizations appLocalizations) => switch (this) { + ProductType.food => appLocalizations.product_type_label_food, + ProductType.beauty => appLocalizations.product_type_label_beauty, + ProductType.petFood => appLocalizations.product_type_label_pet_food, + ProductType.product => appLocalizations.product_type_label_product, + }; + + String getRoadToScoreLabel(final AppLocalizations appLocalizations) => + switch (this) { + ProductType.food => appLocalizations.hey_incomplete_product_message, + ProductType.beauty => + appLocalizations.hey_incomplete_product_message_beauty, + ProductType.petFood => + appLocalizations.hey_incomplete_product_message_pet_food, + ProductType.product => + appLocalizations.hey_incomplete_product_message_product, + }; + + String getShareProductLabel( + final AppLocalizations appLocalizations, + final String url, + ) => + switch (this) { + ProductType.food => appLocalizations.share_product_text( + url, + ), + ProductType.beauty => appLocalizations.share_product_text_beauty( + url, + ), + ProductType.petFood => appLocalizations.share_product_text_pet_food( + url, + ), + ProductType.product => appLocalizations.share_product_text_product( + url, + ), + }; +} 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 ae4551badaf..8416d98432d 100644 --- a/packages/smooth_app/lib/pages/search/search_product_helper.dart +++ b/packages/smooth_app/lib/pages/search/search_product_helper.dart @@ -13,8 +13,8 @@ import 'package:smooth_app/pages/navigator/app_navigator.dart'; import 'package:smooth_app/pages/product/common/product_dialog_helper.dart'; import 'package:smooth_app/pages/product/common/product_query_page_helper.dart'; import 'package:smooth_app/pages/product/common/search_helper.dart'; +import 'package:smooth_app/pages/product/product_type_extensions.dart'; import 'package:smooth_app/query/keywords_product_query.dart'; -import 'package:smooth_app/query/product_query.dart'; /// Search helper dedicated to product search. class SearchProductHelper extends SearchHelper { diff --git a/packages/smooth_app/lib/query/product_query.dart b/packages/smooth_app/lib/query/product_query.dart index 8386ea5f22a..d18794b5cc2 100644 --- a/packages/smooth_app/lib/query/product_query.dart +++ b/packages/smooth_app/lib/query/product_query.dart @@ -1,7 +1,6 @@ import 'dart:ui'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:openfoodfacts/openfoodfacts.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:smooth_app/data_models/preferences/user_preferences.dart'; @@ -9,6 +8,7 @@ import 'package:smooth_app/database/dao_string.dart'; import 'package:smooth_app/database/local_database.dart'; import 'package:smooth_app/helpers/analytics_helper.dart'; import 'package:smooth_app/pages/preferences/user_preferences_dev_mode.dart'; +import 'package:smooth_app/pages/product/product_type_extensions.dart'; import 'package:uuid/uuid.dart'; // ignore: avoid_classes_with_only_static_members @@ -292,49 +292,3 @@ abstract class ProductQuery { ProductField.OWNER_FIELDS, ]; } - -extension ProductTypeExtension on ProductType { - String getDomain() => switch (this) { - ProductType.food => 'openfoodfacts', - ProductType.beauty => 'openbeautyfacts', - ProductType.petFood => 'openpetfoodfacts', - ProductType.product => 'openproductsfacts', - }; - - String getLabel(final AppLocalizations appLocalizations) => switch (this) { - ProductType.food => appLocalizations.product_type_label_food, - ProductType.beauty => appLocalizations.product_type_label_beauty, - ProductType.petFood => appLocalizations.product_type_label_pet_food, - ProductType.product => appLocalizations.product_type_label_product, - }; - - String getRoadToScoreLabel(final AppLocalizations appLocalizations) => - switch (this) { - ProductType.food => appLocalizations.hey_incomplete_product_message, - ProductType.beauty => - appLocalizations.hey_incomplete_product_message_beauty, - ProductType.petFood => - appLocalizations.hey_incomplete_product_message_pet_food, - ProductType.product => - appLocalizations.hey_incomplete_product_message_product, - }; - - String getShareProductLabel( - final AppLocalizations appLocalizations, - final String url, - ) => - switch (this) { - ProductType.food => appLocalizations.share_product_text( - url, - ), - ProductType.beauty => appLocalizations.share_product_text_beauty( - url, - ), - ProductType.petFood => appLocalizations.share_product_text_pet_food( - url, - ), - ProductType.product => appLocalizations.share_product_text_product( - url, - ), - }; -}