From d8aed2fbdc17676294c92e80575e004b74892222 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 27 Feb 2023 22:11:44 +0100 Subject: [PATCH 1/7] Updated the preview of the package in the 'Packaging components ' tab. Preview is now clearer and more coherent with what is shown on the product page. --- .../pages/product/edit_new_packagings.dart | 2 +- .../product/edit_new_packagings_helper.dart | 25 ++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/smooth_app/lib/pages/product/edit_new_packagings.dart b/packages/smooth_app/lib/pages/product/edit_new_packagings.dart index 8b0447e51e7..6321198cc15 100644 --- a/packages/smooth_app/lib/pages/product/edit_new_packagings.dart +++ b/packages/smooth_app/lib/pages/product/edit_new_packagings.dart @@ -99,7 +99,7 @@ class _EditNewPackagingsState extends State { SmoothCard( color: _getSmoothCardColorAlternate(context, index), child: EditNewPackagingsComponent( - title: appLocalizations.edit_packagings_element_title(index + 1), + title: _helpers[index].getSubTitle(), deleteCallback: () => setState(() => _removePackagingAt(deleteIndex)), helper: _helpers[index], diff --git a/packages/smooth_app/lib/pages/product/edit_new_packagings_helper.dart b/packages/smooth_app/lib/pages/product/edit_new_packagings_helper.dart index c267b51d225..01960695846 100644 --- a/packages/smooth_app/lib/pages/product/edit_new_packagings_helper.dart +++ b/packages/smooth_app/lib/pages/product/edit_new_packagings_helper.dart @@ -75,23 +75,36 @@ class EditNewPackagingsHelper { void addIfNotEmpty(final String text) { if (text.isNotEmpty) { - result.add(text); + result.add('$text '); } } - addIfNotEmpty(controllerUnits.text); + + if (controllerUnits.text.isNotEmpty) { + result.add('${controllerUnits.text} x '); + } + addIfNotEmpty(controllerShape.text); - addIfNotEmpty(controllerMaterial.text); - addIfNotEmpty(controllerRecycling.text); - addIfNotEmpty(controllerWeight.text); addIfNotEmpty(controllerQuantity.text); + if (controllerMaterial.text.isNotEmpty & controllerWeight.text.isNotEmpty) { + result.add('(${controllerMaterial.text} : ${controllerWeight.text}g)'); + } + + else if (controllerMaterial.text.isNotEmpty ) { // Therefore controllerWeight.text is empty + result.add('(${controllerMaterial.text})'); + } + if (result.isEmpty) { return null; } - return result.join(' '); + return result.join(''); } + /// Returns the packaging subtitle from the controllers +String getSubTitle() { + return controllerRecycling.text; +} /// Returns the packaging from the controllers. ProductPackaging getPackaging() { final ProductPackaging packaging = ProductPackaging(); From 43cdaab11a9fe5506259994c6620ea11b4128017 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 27 Feb 2023 22:24:52 +0100 Subject: [PATCH 2/7] Autocomplete now gives hints before anything is typed & maxOptionsHeight fixed - The autocomplete now gives the most common answers for the field before user start typing. (Useful for packaging material, recycling...) - Fixing _AssertionError 'maxOptionsHeight >= 0': is not true: The old formula could give negative values. It could also create an unreadable autocomplete if the field was too close to the keyboard. --- .../product/simple_input_text_field.dart | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/packages/smooth_app/lib/pages/product/simple_input_text_field.dart b/packages/smooth_app/lib/pages/product/simple_input_text_field.dart index 58e8c1b3e5b..12e5f96ed2c 100644 --- a/packages/smooth_app/lib/pages/product/simple_input_text_field.dart +++ b/packages/smooth_app/lib/pages/product/simple_input_text_field.dart @@ -40,19 +40,16 @@ class SimpleInputTextField extends StatelessWidget { optionsBuilder: (final TextEditingValue value) async { final String input = value.text.trim(); - if (input.isEmpty) { - return []; - } if (tagType == null) { return []; } - + return OpenFoodAPIClient.getSuggestions( tagType!, language: ProductQuery.getLanguage()!, - limit: 1000000, // lower max count on the server anyway - input: value.text.trim(), + limit: 15, + input: input, ); }, fieldViewBuilder: (BuildContext context, @@ -100,17 +97,7 @@ class SimpleInputTextField extends StatelessWidget { options: options, // Width = Row width - horizontal padding maxOptionsWidth: constraints.maxWidth - (LARGE_SPACE * 2), - maxOptionsHeight: screenHeight - - (keyboardHeight == 0 - ? kBottomNavigationBarHeight - : keyboardHeight) - - widgetPosition - - // Vertical padding - (LARGE_SPACE * 2) - - // Height of the TextField - (DefaultTextStyle.of(context).style.fontSize ?? 0) - - // Elevation - 4.0, + maxOptionsHeight: screenHeight/3, ); }, ), From 3ee60ab7b0dc80b86a72e40cf5e04f0c52b6b4e6 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 28 Feb 2023 16:13:16 +0100 Subject: [PATCH 3/7] Removed Autocomplete now gives hints before anything is typed. @monsieurtanuki as addressed the issue in #3750 without disturbing old default behavior of the widget. --- .../smooth_app/lib/pages/product/simple_input_text_field.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/smooth_app/lib/pages/product/simple_input_text_field.dart b/packages/smooth_app/lib/pages/product/simple_input_text_field.dart index 12e5f96ed2c..0fac180cf30 100644 --- a/packages/smooth_app/lib/pages/product/simple_input_text_field.dart +++ b/packages/smooth_app/lib/pages/product/simple_input_text_field.dart @@ -40,6 +40,9 @@ class SimpleInputTextField extends StatelessWidget { optionsBuilder: (final TextEditingValue value) async { final String input = value.text.trim(); + if (input.isEmpty) { + return []; + } if (tagType == null) { return []; From 4cbea5f4b6f7fcdeeff6e277ca3b4de9f4a5deb1 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 28 Feb 2023 19:25:37 +0100 Subject: [PATCH 4/7] Comment explaining the limit of suggestions. --- .../smooth_app/lib/pages/product/simple_input_text_field.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/smooth_app/lib/pages/product/simple_input_text_field.dart b/packages/smooth_app/lib/pages/product/simple_input_text_field.dart index 84cc8c76793..4e9e48a7e45 100644 --- a/packages/smooth_app/lib/pages/product/simple_input_text_field.dart +++ b/packages/smooth_app/lib/pages/product/simple_input_text_field.dart @@ -60,7 +60,7 @@ class SimpleInputTextField extends StatelessWidget { categories: categories, shape: shapeProvider?.call(), user: ProductQuery.getUser(), - limit: 15, + limit: 15, // number of suggestions the user can scroll through: compromise between quantity and readability of the suggestions input: input, ); }, From e8081a04cae1f01d2003968a69d7f5904924af3f Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 28 Feb 2023 19:29:08 +0100 Subject: [PATCH 5/7] Taking into account the case 'Material empty' and 'Weight not empty' & format --- .../product/edit_new_packagings_helper.dart | 19 ++++++++++++------- .../product/simple_input_text_field.dart | 7 ++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/smooth_app/lib/pages/product/edit_new_packagings_helper.dart b/packages/smooth_app/lib/pages/product/edit_new_packagings_helper.dart index 01960695846..03adf96a92f 100644 --- a/packages/smooth_app/lib/pages/product/edit_new_packagings_helper.dart +++ b/packages/smooth_app/lib/pages/product/edit_new_packagings_helper.dart @@ -79,21 +79,25 @@ class EditNewPackagingsHelper { } } - if (controllerUnits.text.isNotEmpty) { result.add('${controllerUnits.text} x '); } - + addIfNotEmpty(controllerShape.text); addIfNotEmpty(controllerQuantity.text); if (controllerMaterial.text.isNotEmpty & controllerWeight.text.isNotEmpty) { - result.add('(${controllerMaterial.text} : ${controllerWeight.text}g)'); + result.add('(${controllerMaterial.text}: ${controllerWeight.text}g)'); + } + + if (controllerMaterial.text.isNotEmpty & controllerWeight.text.isEmpty) { + result.add('(${controllerMaterial.text})'); } - else if (controllerMaterial.text.isNotEmpty ) { // Therefore controllerWeight.text is empty - result.add('(${controllerMaterial.text})'); + if (controllerMaterial.text.isEmpty & controllerWeight.text.isNotEmpty) { + result.add('(${controllerWeight.text}g)'); } + // And nothing is added if they are both empty. if (result.isEmpty) { return null; @@ -102,9 +106,10 @@ class EditNewPackagingsHelper { } /// Returns the packaging subtitle from the controllers -String getSubTitle() { + String getSubTitle() { return controllerRecycling.text; -} + } + /// Returns the packaging from the controllers. ProductPackaging getPackaging() { final ProductPackaging packaging = ProductPackaging(); diff --git a/packages/smooth_app/lib/pages/product/simple_input_text_field.dart b/packages/smooth_app/lib/pages/product/simple_input_text_field.dart index 4e9e48a7e45..a6540cd7797 100644 --- a/packages/smooth_app/lib/pages/product/simple_input_text_field.dart +++ b/packages/smooth_app/lib/pages/product/simple_input_text_field.dart @@ -52,7 +52,7 @@ class SimpleInputTextField extends StatelessWidget { if (input.length < minLengthForSuggestions) { return []; } - + return OpenFoodAPIClient.getSuggestions( tagType!, language: ProductQuery.getLanguage()!, @@ -60,7 +60,8 @@ class SimpleInputTextField extends StatelessWidget { categories: categories, shape: shapeProvider?.call(), user: ProductQuery.getUser(), - limit: 15, // number of suggestions the user can scroll through: compromise between quantity and readability of the suggestions + limit: + 15, // number of suggestions the user can scroll through: compromise between quantity and readability of the suggestions input: input, ); }, @@ -109,7 +110,7 @@ class SimpleInputTextField extends StatelessWidget { options: options, // Width = Row width - horizontal padding maxOptionsWidth: constraints.maxWidth - (LARGE_SPACE * 2), - maxOptionsHeight: screenHeight/3, + maxOptionsHeight: screenHeight / 3, ); }, ), From 4b7b14005c2c9382cd391d6437d8b9386c38ee92 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 28 Feb 2023 19:35:35 +0100 Subject: [PATCH 6/7] Removing unused variables This variables where previously used in the formula of maxOptionsHeight --- .../lib/pages/product/simple_input_text_field.dart | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/smooth_app/lib/pages/product/simple_input_text_field.dart b/packages/smooth_app/lib/pages/product/simple_input_text_field.dart index a6540cd7797..e242f951de1 100644 --- a/packages/smooth_app/lib/pages/product/simple_input_text_field.dart +++ b/packages/smooth_app/lib/pages/product/simple_input_text_field.dart @@ -94,14 +94,6 @@ class SimpleInputTextField extends StatelessWidget { ) { final double screenHeight = MediaQuery.of(context).size.height; - final double keyboardHeight = - MediaQuery.of(lContext).viewInsets.bottom; - - final double widgetPosition = - (context.findRenderObject() as RenderBox?) - ?.localToGlobal(Offset.zero) - .dy ?? - 0.0; return AutocompleteOptions( displayStringForOption: From ee90a53656c5df40bf2347b1b4cb21d6e3f1de9d Mon Sep 17 00:00:00 2001 From: monsieurtanuki Date: Thu, 2 Mar 2023 19:10:12 +0100 Subject: [PATCH 7/7] Update packages/smooth_app/lib/pages/product/edit_new_packagings_helper.dart --- .../product/edit_new_packagings_helper.dart | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/smooth_app/lib/pages/product/edit_new_packagings_helper.dart b/packages/smooth_app/lib/pages/product/edit_new_packagings_helper.dart index 03adf96a92f..be9d3bb0f88 100644 --- a/packages/smooth_app/lib/pages/product/edit_new_packagings_helper.dart +++ b/packages/smooth_app/lib/pages/product/edit_new_packagings_helper.dart @@ -86,18 +86,15 @@ class EditNewPackagingsHelper { addIfNotEmpty(controllerShape.text); addIfNotEmpty(controllerQuantity.text); - if (controllerMaterial.text.isNotEmpty & controllerWeight.text.isNotEmpty) { - result.add('(${controllerMaterial.text}: ${controllerWeight.text}g)'); - } - - if (controllerMaterial.text.isNotEmpty & controllerWeight.text.isEmpty) { - result.add('(${controllerMaterial.text})'); - } - - if (controllerMaterial.text.isEmpty & controllerWeight.text.isNotEmpty) { + if (controllerMaterial.text.isNotEmpty) { + if (controllerWeight.text.isNotEmpty) { + result.add('(${controllerMaterial.text}: ${controllerWeight.text}g)'); + } else { + result.add('(${controllerMaterial.text})'); + } + } else if (controllerWeight.text.isNotEmpty) { result.add('(${controllerWeight.text}g)'); } - // And nothing is added if they are both empty. if (result.isEmpty) { return null;