openfoodfacts / smooth-app

🤳🥫 The new Open Food Facts mobile application for Android and iOS, crafted with Flutter and Dart
https://world.openfoodfacts.org/open-food-facts-mobile-app?utm_source=off&utf_medium=web&utm_campaign=github-repo
Apache License 2.0
853 stars 282 forks source link

Nutrition amounts are saved without decimal separator 1.51% → 151% #3723

Closed fuddl closed 1 year ago

fuddl commented 1 year ago

What

I cannot enter nutrient amounts with decimal seperator because it will dissappear after saving.

Steps to reproduce the behavior

  1. Open a product
  2. Edit Nutrition facts
  3. enter a number with a decimal seperator
  4. save
  5. review nutrition facts

Expected behavior

The nutrient should have an amount with a decimal seperator.

Screenshot

What goes in What comes out
IMG_2316 IMG_2317

Smartphone model

Additional context

Please note: on the screenshots you can see I'm only able enter amounts with a , for a decimal seperator. I don't know why. I would expect . instead.

sarkartanmay393 commented 1 year ago

I would like to give it a try.

teolemon commented 1 year ago

@galnaf is having the same issue on packaging

https://user-images.githubusercontent.com/1689815/220296815-cc36c997-b509-41a0-8e06-42dfd3b5e5a6.MP4

monsieurtanuki commented 1 year ago

That makes sense, it's the same widget used in both cases. @sarkartanmay393 First, did you reproduce the bug with the latest code? There were recent code changes, actually.

teolemon commented 1 year ago

Bumping to P0

monsieurtanuki commented 1 year ago

I found what probably causes the problem: some kind of discrepancy between the input and the output format

final decimalNumberFormat = NumberFormat(
  '####0.#####',
  'en_US',
);
final double toto1 = decimalNumberFormat.parse('6.85').toDouble();
print('$toto1'); // 6.85
final double toto2 = decimalNumberFormat.parse('6,85').toDouble();
print('$toto2'); // 685.0

In the latest video the problem is that the keyboard is French-like (comma is the decimal separator) and the app language is English. Which means we write 6,85 with the keyboard, and we change that into 685 as we parse it in English.

The fix would be: whatever the keyboard displays, we should replace the decimal separator with the app language decimal separator before parsing it.

I don't think I'll be able to fix it (or to test my fix) with my limited access to a computer. I'd be happy to help whoever wants to fix it.

Additional info: we replace decimal separators in method formatEditUpdate in class DecimalSeparatorRewriter, and perhaps that's where the fix should be.

teolemon commented 1 year ago

I somehow managed to delete all nutrients of a product without really trying (see the history in https://world.openfoodfacts.org/product/1234567890123/dev-test-do-not-delete). I need to reproduce the issue once more. However, the comma thing comes through ok

teolemon commented 1 year ago

Can't reproduce.. Go figure. That looks good to me

monsieurtanuki commented 1 year ago

@teolemon Just curious: were you connected as hungergames?

February 23, 2023 at 1:41:48 PM CET - hungergames Data (Changed: data_sources) -- Nutriments (Changed: carbohydrates) (Deleted: energy-kcal, energy, fat, saturated-fat, sugars, proteins, salt, sodium) - (app)- Smoothie - OpenFoodFacts - 4.4.0+968 - android+T2B3.230109.004 - 4c2e8196-346f-42d4-8265-697a90efcc6c - view

The Data (Changed: data_sources) is a bit strange, as it does not happen that often. Where does that come from?