-
-
Notifications
You must be signed in to change notification settings - Fork 66
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 Nutriment modifiers #910
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @g123k!
My main remarks:
- we would probably be better off with a breaking change, and from now on use only a
Map<String, NutrientValue>
, to make it obvious for the developers that they can use potentially modified data withgetNutrientValue
only - if instead we keep the old methods (e.g.
getValue
) as merely "deprecated", the developers will use potentially wrong data. And in that caseNutrientValue
has no real added value. - if we could get rid of French spelling it wouldn't hurt ;)
} | ||
} | ||
|
||
enum NutrimentModifier { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Should be spelled
NutrientModifier
- Could implement
OffTagged
- Not sure if we need
@JsonValue
here, which is redundant with thevalue
field - Would rename field
value
asmodifier
@@ -122,3 +194,71 @@ class Nutriments extends JsonObject { | |||
|
|||
static Map<String, dynamic> toJsonHelper(Nutriments? n) => n?.toJson() ?? {}; | |||
} | |||
|
|||
class NutrimentValue { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Should be spelled
NutrientValue
- But I'm not convinced of the added value of this class.
@@ -1,7 +1,9 @@ | |||
import 'nutrient.dart'; | |||
import 'per_size.dart'; | |||
import 'package:json_annotation/json_annotation.dart'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we need it.
_map[tag] = NutrimentValue._fromMap(map, tag); | ||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe wrong, not sure, depends on the received data:
- are the value and the modifier merged together into a single
String
, like'sugars_100g': '<0.5'
- or do we get the value in a field and the modifier in another, like
'sugars_100g': 0.5,'sugars_100g_modifier':'<'
If it's (2), the continue
is wrong.
I was hesitating between the two solutions : a full breaking change path or not. |
Hi everyone,
The idea of this PR is to support nutriment modifiers from the JSON.
Here are the different cases:
-
: no value available on the package>
: more than a value<
: less than a value~
: approximately this valueFor now this is just a draft (tests are missing for example).
It's basically to receive feedback for the implementation.
A JSON example with all values with a
-
: