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: Support for '-' in nutritional values #4909

Merged
merged 2 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class AddBasicDetailsPage extends StatefulWidget {

class _AddBasicDetailsPageState extends State<AddBasicDetailsPage> {
final TextEditingController _productNameController = TextEditingController();
late final TextEditingControllerWithInitialValue _brandNameController;
late final TextEditingControllerWithInitialValue _weightController;
late final TextEditingControllerWithHistory _brandNameController;
late final TextEditingControllerWithHistory _weightController;

final double _heightSpace = LARGE_SPACE;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
Expand All @@ -47,10 +47,10 @@ class _AddBasicDetailsPageState extends State<AddBasicDetailsPage> {
void initState() {
super.initState();
_product = widget.product;
_weightController = TextEditingControllerWithInitialValue(
_weightController = TextEditingControllerWithHistory(
text: MultilingualHelper.getCleanText(_product.quantity ?? ''),
);
_brandNameController = TextEditingControllerWithInitialValue(
_brandNameController = TextEditingControllerWithHistory(
text: _formatProductBrands(_product.brands),
);
_multilingualHelper = MultilingualHelper(
Expand Down Expand Up @@ -230,11 +230,11 @@ class _AddBasicDetailsPageState extends State<AddBasicDetailsPage> {

Product getBasicProduct() => Product(barcode: _product.barcode);

if (_weightController.valueHasChanged) {
if (_weightController.isDifferentFromInitialValue) {
result ??= getBasicProduct();
result.quantity = _weightController.text;
}
if (_brandNameController.valueHasChanged) {
if (_brandNameController.isDifferentFromInitialValue) {
result ??= getBasicProduct();
result.brands = _formatProductBrands(_brandNameController.text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AddOtherDetailsPage extends StatefulWidget {
}

class _AddOtherDetailsPageState extends State<AddOtherDetailsPage> {
late final TextEditingControllerWithInitialValue _websiteController;
late final TextEditingControllerWithHistory _websiteController;

final double _heightSpace = LARGE_SPACE;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
Expand All @@ -36,7 +36,7 @@ class _AddOtherDetailsPageState extends State<AddOtherDetailsPage> {
super.initState();
_product = widget.product;
_websiteController =
TextEditingControllerWithInitialValue(text: _product.website ?? '');
TextEditingControllerWithHistory(text: _product.website ?? '');
}

@override
Expand Down Expand Up @@ -111,7 +111,7 @@ class _AddOtherDetailsPageState extends State<AddOtherDetailsPage> {
}

/// Returns `true` if any value differs with initial state.
bool _isEdited() => _websiteController.valueHasChanged;
bool _isEdited() => _websiteController.isDifferentFromInitialValue;

/// Exits the page if the [flag] is `true`.
void _exitPage(final bool flag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class NutritionAddNutrientButton extends StatelessWidget {
a.name!.compareTo(b.name!));
List<OrderedNutrient> filteredList =
List<OrderedNutrient>.from(leftovers);
final TextEditingControllerWithInitialValue nutritionTextController =
TextEditingControllerWithInitialValue();
final TextEditingControllerWithHistory nutritionTextController =
TextEditingControllerWithHistory();
final ScrollController controller = ScrollController();

final OrderedNutrient? selected = await showDialog<OrderedNutrient>(
Expand Down
Loading