Skip to content

Conversation

@mwk24
Copy link

@mwk24 mwk24 commented Jul 9, 2023

I was just needing 3 countries, and it's much easier to just show them in the order specified in the countries array to the widget.

Thanks!

@FarhanSyedain
Copy link
Collaborator

Please provide full details on what your contribution does.
Provide screen shots from this new change as well as explain in detail what the change does

Copy link
Collaborator

@FarhanSyedain FarhanSyedain left a comment

Choose a reason for hiding this comment

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

Explain what exactly is your PR trying to solve.
How does your code effect the behavior of the library?

Comment on lines +22 to 27
List filteredList = countries
.map((countryCode) => jsonList.firstWhere((country) => country[PropertyName] == countryCode,
orElse: () => null))
.toList();

return filteredList.map((country) => Country.fromJson(country)).toList();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe let's return Country.fromJson(country) inside the first loop instead of in another loop on 27?

Suggested change
List filteredList = countries
.map((countryCode) => jsonList.firstWhere((country) => country[PropertyName] == countryCode,
orElse: () => null))
.toList();
return filteredList.map((country) => Country.fromJson(country)).toList();
final filteredList = countries.map((countryCode) {
final _country = jsonList.firstWhere(
(country) => country[PropertyName] == countryCode,
orElse: () => null,
);
if (_country == null) return null;
return Country.fromJson(_country);
}).where((c) => c != null).toList();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants