Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Clearer 'Packaging components' preview and modified the maximum size of the autocomplete tab. #3744

Merged
merged 10 commits into from
Mar 2, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class _EditNewPackagingsState extends State<EditNewPackagings> {
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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +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) {
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)');
}

if (result.isEmpty) {
return null;
}
return result.join(' ');
return result.join('');
thomas-algo marked this conversation as resolved.
Show resolved Hide resolved
}

/// Returns the packaging subtitle from the controllers
String getSubTitle() {
return controllerRecycling.text;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Says who?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the packaging recycling info to the subtitle of the widget for readability (cf first screenshot). This function generate this subtitle.

}

/// Returns the packaging from the controllers.
Expand Down
25 changes: 4 additions & 21 deletions packages/smooth_app/lib/pages/product/simple_input_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ class SimpleInputTextField extends StatelessWidget {
categories: categories,
shape: shapeProvider?.call(),
user: ProductQuery.getUser(),
limit: 1000000, // lower max count on the server anyway
input: value.text.trim(),
limit:
15, // number of suggestions the user can scroll through: compromise between quantity and readability of the suggestions
input: input,
);
},
fieldViewBuilder: (BuildContext context,
Expand Down Expand Up @@ -93,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<String>(
displayStringForOption:
Expand All @@ -109,17 +102,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,
);
},
),
Expand Down