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: Allow to get OpenFoodFactsCountry from countryCode #314
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5b6318c
feat: Allow to get OpenFoodFactsCountry from countryCode
M123-dev 6ba1425
Added comment
M123-dev f1ae17a
feat: New CountryHelper class
M123-dev deeb006
style: Automatic import sorting
M123-dev 743d773
Update CountryHelper.dart
M123-dev 06b1049
Applied code review
M123-dev File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does not work for an unknown
code
: crashes, instead of an expectednull
.firstWhere
is not adequate, as it never returns null.Your previous syntax was correct (it's just that the
return;
was useless).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.
Yes I know that it theoretically worked but it didn't make sense since the extension only worked for specific values of the enum, not for the enum itself, so there you would have to write
OpenFoodFactsCountry.FRANCE.fromCountryCode('de')
which would return germany, that's why I moved it and now the structure is similar to the one in the OpenFoodFactsLanguage.Regarding the null problem, it's not possible to return null from
orElse
so we could either add a UNKNOW value to the enum as in the OpenFoodFactsLanguage but I would rather just switch back to the old forEach loop.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.
I see,
static
methods don't seem to be allowed inextension
s.Similarly to what you wrote initially, and which seems to work:
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.
Or even better (I don't find the dart map methods always 100% relevant):
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.
Changed it, good suggestion