Skip to content

Conversation

@piedcipher
Copy link
Contributor

@piedcipher piedcipher commented Jan 30, 2025

Fixes flutter/website#11632


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:
  • See our contributor guide for general expectations for PRs.
  • Larger or significant changes should be discussed in an issue before creating a PR.
  • Contributions to our repos should follow the Dart style guide and use dart format.

Note that this repository uses Gerrit for code reviews. Your pull request will be automatically converted into a Gerrit CL and a link to the CL written into this PR. The review will happen on Gerrit but you can also push additional commits to this PR to update the code review.

@copybara-service
Copy link

Thank you for your contribution! This project uses Gerrit for code reviews. Your pull request has automatically been converted into a code review at:

https://dart-review.googlesource.com/c/sdk/+/406781

Please wait for a developer to review your code review at the above link; you can speed up the review if you sign into Gerrit and manually add a reviewer that has recently worked on the relevant code. See CONTRIBUTING.md to learn how to upload changes to Gerrit directly.

Additional commits pushed to this PR will update both the PR and the corresponding Gerrit CL. After the review is complete on the CL, your reviewer will merge the CL (automatically closing this PR).

@copybara-service
Copy link

https://dart-review.googlesource.com/c/sdk/+/406781 has been updated with the latest commits from this pull request.

Copy link
Member

@mraleph mraleph left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution.

It is true that the last example contains a bug (5 instead of 6). However all other change are unnecessary because HashMap is unordered. See my comments.

/// final gasGiants = {6: 'Jupiter', 5: 'Saturn'};
/// planets.addEntries(gasGiants.entries);
/// print(planets); // fx {5: Saturn, 6: Jupiter, 3: Earth, 4: Mars}
/// print(planets); // fx {3: Earth, 4: Mars, 6: Jupiter, 5: Saturn}
Copy link
Member

Choose a reason for hiding this comment

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

That's not a bug. HashMap is unordered which means any output is possible here. That's why it says fx.

Consider instead

/// print(planets);  // fx {5: Saturn, 6: Jupiter, 3: Earth, 4: Mars}, no particular order of keys is guaranteed

or something similar

cc @lrhn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

/// // 5 Saturn
/// // 4 Mars
/// // 3 Earth
/// // 4 Mars
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary change. You can undo this as explained above order is not guaranteed with HashMap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

/// ```
/// To remove an entry with a specific key, use [remove].
/// ```dart continued
/// final removeValue = planets.remove(5);
Copy link
Member

Choose a reason for hiding this comment

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

A smaller change would be to just replace 5 by 6 here and not change subsequent lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@copybara-service
Copy link

https://dart-review.googlesource.com/c/sdk/+/406781 has been updated with the latest commits from this pull request.

3 similar comments
@copybara-service
Copy link

https://dart-review.googlesource.com/c/sdk/+/406781 has been updated with the latest commits from this pull request.

@copybara-service
Copy link

https://dart-review.googlesource.com/c/sdk/+/406781 has been updated with the latest commits from this pull request.

@copybara-service
Copy link

https://dart-review.googlesource.com/c/sdk/+/406781 has been updated with the latest commits from this pull request.

Copy link
Member

@mraleph mraleph left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you.

I have submitted corresponding Gerrit CL to CQ. Note: when CQ submits CL this PR will close without merging. That does not mean we rejected PR - that's just how things work, GitHub is just a mirror of an upstream repository.

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.

Wrong output examples in HashMap section of the Flutter documentation

2 participants