Skip to content

Commit

Permalink
feat: 3749 - improvements for packaging suggestions (#3750)
Browse files Browse the repository at this point in the history
* Revert "feat: 3585 - upgrade to flutter 3.7 (#3666)"

This reverts commit ad46236.

* feat: 3749 - improvements for packaging suggestions

Impacted files:
* `edit_new_packagings.dart`: added categories parameter for suggestions
* `edit_new_packagings_component.dart`: added categories field; added categories parameters for shape search; added categories and shape parameters for material search; added specific minLengthForSuggestions parameter set to 0 for shape and material search
* `simple_input_text_field.dart`: added minLengthForSuggestions, categories and shape fields; added categories, shape and country parameters for `getSuggestions`
  • Loading branch information
monsieurtanuki committed Feb 28, 2023
1 parent c281395 commit 90a9bc5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class _EditNewPackagingsState extends State<EditNewPackagings> {
deleteCallback: () =>
setState(() => _removePackagingAt(deleteIndex)),
helper: _helpers[index],
categories: widget.product.categories,
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ class EditNewPackagingsComponent extends StatefulWidget {
required this.title,
required this.deleteCallback,
required this.helper,
required this.categories,
});

final String title;
final VoidCallback deleteCallback;
final EditNewPackagingsHelper helper;
final String? categories;

@override
State<EditNewPackagingsComponent> createState() =>
Expand Down Expand Up @@ -54,6 +56,8 @@ class _EditNewPackagingsComponentState
tagType: TagType.PACKAGING_SHAPES,
iconName: 'shape',
iconColor: iconColor,
minLengthForSuggestions: 0,
categories: widget.categories,
),
_EditTextLine(
title: appLocalizations.edit_packagings_element_field_material,
Expand All @@ -62,6 +66,9 @@ class _EditNewPackagingsComponentState
iconName: 'material',
iconColor: iconColor,
hint: appLocalizations.edit_packagings_element_hint_material,
minLengthForSuggestions: 0,
categories: widget.categories,
shapeProvider: () => widget.helper.controllerShape.text,
),
_EditTextLine(
title: appLocalizations.edit_packagings_element_field_recycling,
Expand Down Expand Up @@ -123,6 +130,9 @@ class _EditTextLine extends StatefulWidget {
required this.iconColor,
this.hint,
this.tagType,
this.minLengthForSuggestions = 1,
this.categories,
this.shapeProvider,
});

final String title;
Expand All @@ -131,6 +141,9 @@ class _EditTextLine extends StatefulWidget {
final String iconName;
final Color? iconColor;
final String? hint;
final int minLengthForSuggestions;
final String? categories;
final String? Function()? shapeProvider;

@override
State<_EditTextLine> createState() => _EditTextLineState();
Expand Down Expand Up @@ -179,6 +192,9 @@ class _EditTextLineState extends State<_EditTextLine> {
hintText: '',
controller: widget.controller,
withClearButton: true,
minLengthForSuggestions: widget.minLengthForSuggestions,
categories: widget.categories,
shapeProvider: widget.shapeProvider,
),
),
),
Expand Down
17 changes: 13 additions & 4 deletions packages/smooth_app/lib/pages/product/simple_input_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class SimpleInputTextField extends StatelessWidget {
required this.hintText,
required this.controller,
this.withClearButton = false,
this.minLengthForSuggestions = 1,
this.categories,
this.shapeProvider,
});

final FocusNode focusNode;
Expand All @@ -23,6 +26,9 @@ class SimpleInputTextField extends StatelessWidget {
final String hintText;
final TextEditingController controller;
final bool withClearButton;
final int minLengthForSuggestions;
final String? categories;
final String? Function()? shapeProvider;

@override
Widget build(BuildContext context) => Padding(
Expand All @@ -38,19 +44,22 @@ class SimpleInputTextField extends StatelessWidget {
focusNode: focusNode,
textEditingController: controller,
optionsBuilder: (final TextEditingValue value) async {
final String input = value.text.trim();

if (input.isEmpty) {
if (tagType == null) {
return <String>[];
}

if (tagType == null) {
final String input = value.text.trim();
if (input.length < minLengthForSuggestions) {
return <String>[];
}

return OpenFoodAPIClient.getSuggestions(
tagType!,
language: ProductQuery.getLanguage()!,
country: ProductQuery.getCountry(),
categories: categories,
shape: shapeProvider?.call(),
user: ProductQuery.getUser(),
limit: 1000000, // lower max count on the server anyway
input: value.text.trim(),
);
Expand Down

0 comments on commit 90a9bc5

Please sign in to comment.