Skip to content
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

Wrong output examples in HashMap section of the Flutter documentation #11632

Open
1 task done
LaPyaeOo opened this issue Jan 28, 2025 · 2 comments · May be fixed by dart-lang/sdk#60014
Open
1 task done

Wrong output examples in HashMap section of the Flutter documentation #11632

LaPyaeOo opened this issue Jan 28, 2025 · 2 comments · May be fixed by dart-lang/sdk#60014
Labels
co.PRs-welcome Contributors encouraged to file a PR e1-hours Effort: < 8 hrs from.page-issue Reported in a reader-filed concern p2-medium Necessary but not urgent concern. Resolve when possible.

Comments

@LaPyaeOo
Copy link

LaPyaeOo commented Jan 28, 2025

Page URL

https://api.flutter.dev/flutter/dart-collection/HashMap-class.html#:~:text=A%20hash%2Dtable%20based%20implementation,();%20//%20Is%20a%20HashMap

Page source

Example code snippet is wrong

Describe the problem

I found two examples are shown in the HashMap section of the documentation.

1st
Adding data to HashMap with addEntries() method. Actually addEntries() method adds a pair of map values from the last of Map.
But in example add from the first.

Error in documentation

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

2nd
In this code removing the key from HashMap is 5 but in the example output, the value of the plants still contains a pair of 5.

Error in documentation

final removeValue = planets.remove(5);
print(removeValue); // Jupiter
print(planets); // fx {4: Mars, 3: Earth, 5: Saturn}

Expected fix

Expected result for bug - 1

import 'dart:collection';

void main() {
  final Map<int, String> planets = HashMap();
  planets[3] = 'Earth';
  planets.addAll({4: 'Mars'});
  final gasGiants = {6: 'Jupiter', 5: 'Saturn'};
  planets.addEntries(gasGiants.entries);
  print(planets); // {3: Earth, 4: Mars, 6: Jupiter, 5: Saturn}
}

Expected result for bug - 2

final removeValue = planets.remove(5);
print(removeValue); // Jupiter
print(planets); // fx {4: Mars, 3: Earth}

Additional context

No response

I would like to fix this problem.

  • I will try and fix this problem on docs.flutter.dev.
@LaPyaeOo LaPyaeOo added the from.page-issue Reported in a reader-filed concern label Jan 28, 2025
@sfshaza2 sfshaza2 added p2-medium Necessary but not urgent concern. Resolve when possible. co.PRs-welcome Contributors encouraged to file a PR e1-hours Effort: < 8 hrs labels Jan 28, 2025
@piedcipher
Copy link
Member

piedcipher commented Jan 30, 2025

Issues is in dart-lang/SDK repo - https://github.com/dart-lang/sdk/blob/main/sdk/lib/collection/hash_map.dart

@piedcipher piedcipher linked a pull request Jan 30, 2025 that will close this issue
1 task
@piedcipher
Copy link
Member

Expected result for second should be - {3: Earth, 4: Mars, 6: Jupiter}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
co.PRs-welcome Contributors encouraged to file a PR e1-hours Effort: < 8 hrs from.page-issue Reported in a reader-filed concern p2-medium Necessary but not urgent concern. Resolve when possible.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants