Skip to content

fix: MaterialColor Swatch Map comparison - #61974

Merged
fluttergithubbot merged 7 commits into
flutter:masterfrom
ayaankhan98:master
Aug 6, 2020
Merged

fluttergithubbot merged 7 commits into
flutter:masterfrom
ayaankhan98:master

Conversation

@ayaankhan98

@ayaankhan98 ayaankhan98 commented Jul 21, 2020 •

Copy link
Copy Markdown
Contributor

Description

fixed the map comparison bug.
since _swatch is a Map and the comparison other._swatch == _swatch; will always return false if the Maps have different hashCodes.

therefore the == is replaced by MapEquality().equals(other._swatch,_swatch)

Related Issues

Fixes #61888

Tests

This is the bug reproducible code

import 'package:flutter/material.dart';

void main() {
 var map = {0:Colors.lightBlue,1:Colors.deepOrange,2:Colors.blueGrey};
 var first = new MaterialColor(0, map);
 var second = new MaterialColor(0, map);
 var third = new MaterialColor(0, {0:Colors.lightBlue,1:Colors.deepOrange,2:Colors.blueGrey});
 print("Comparison of the same map object in MaterialColor constructor: " + (first == second).toString());
 print("Comparison of different map objects with same values in MaterialColor constructor: " + (first == third).toString());
}

before changing the == by MapEquality().equals(other._swatch,_swatch)
the output was

I/flutter (17640): Comparison of the same map object in MaterialColor constructor: true
I/flutter (17640): Comparison of different map objects with same values in MaterialColor constructor: false

after implementing changes the output is as expected

I/flutter (17640): Comparison of the same map object in MaterialColor constructor: true
I/flutter (17640): Comparison of different map objects with same values in MaterialColor constructor: true

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label Jul 21, 2020
@fluttergithubbot

Copy link
Copy Markdown
Contributor

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @ayaankhan98 welcome! And thank you for the contribution!

Can you revert the unrelated formatting changes here? You can refer to the Flutter Style Guide here.
The analyzer also appears to have caught some exceptions here:

info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:207:33 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:208:20 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:209:20 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:220:33 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:390:33 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:391:20 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:392:20 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:403:33 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:447:33 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:448:43 • always_put_control_body_on_new_line
   info • Prefer const with constant constructors • packages/flutter/lib/src/painting/colors.dart:451:9 • prefer_const_constructors
   info • Specify type annotations • packages/flutter/lib/src/painting/colors.dart:451:9 • always_specify_types
  error • Missing type arguments for generic type 'MapEquality<dynamic, dynamic>' • packages/flutter/lib/src/painting/colors.dart:451:9 • implicit_dynamic_type

Lastly, this should also have a test. That will make sure this works as intended, and more importantly it will ensure it is not undone later by another change.

@ayaankhan98

Copy link
Copy Markdown
Contributor Author

Hi @ayaankhan98 welcome! And thank you for the contribution!

Can you revert the unrelated formatting changes here? You can refer to the Flutter Style Guide here.
The analyzer also appears to have caught some exceptions here:

info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:207:33 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:208:20 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:209:20 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:220:33 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:390:33 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:391:20 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:392:20 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:403:33 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:447:33 • always_put_control_body_on_new_line
   info • Separate the control structure expression from its statement • packages/flutter/lib/src/painting/colors.dart:448:43 • always_put_control_body_on_new_line
   info • Prefer const with constant constructors • packages/flutter/lib/src/painting/colors.dart:451:9 • prefer_const_constructors
   info • Specify type annotations • packages/flutter/lib/src/painting/colors.dart:451:9 • always_specify_types
  error • Missing type arguments for generic type 'MapEquality<dynamic, dynamic>' • packages/flutter/lib/src/painting/colors.dart:451:9 • implicit_dynamic_type

Lastly, this should also have a test. That will make sure this works as intended, and more importantly it will ensure it is not undone later by another change.

okay Thanks @Piinks i will fix these issues soon.

@ayaankhan98

Copy link
Copy Markdown
Contributor Author

Lastly, this should also have a test. That will make sure this works as intended, and more importantly it will ensure it is not undone later by another change.

@Piinks where should i place test for this, in flutter/packages/flutter/test/material/colors_test.dart or in flutter/packages/flutter/test/painting/colors_test.dart

@Piinks

Piinks commented Jul 22, 2020

Copy link
Copy Markdown
Contributor

@Piinks where should i place test for this, in flutter/packages/flutter/test/material/colors_test.dart or in flutter/packages/flutter/test/painting/colors_test.dart

✅ flutter/packages/flutter/test/painting/colors_test.dart - that should be a good place! Thanks! :)

@markusaksli-nc markusaksli-nc linked an issue Jul 22, 2020 that may be closed by this pull request
Comment thread packages/flutter/lib/src/painting/colors.dart Outdated

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for updating this! Just a few nits. :)

Comment thread packages/flutter/lib/src/painting/colors.dart Outdated
Comment thread packages/flutter/test/painting/colors_test.dart Outdated

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thank you!

The failing checks are not related to this change. Upstream is actually broken right now with this version solving problem: #62146. That will have to be fixed first, then this PR rebased for the checks to pass.

@ayaankhan98

Copy link
Copy Markdown
Contributor Author

The failing checks are not related to this change. Upstream is actually broken right now with this version solving problem: #62146. That will have to be fixed first, then this PR rebased for the checks to pass.

Okay, Thanks for help :)

@goderbauer

Copy link
Copy Markdown
Member

@ayaankhan98 The issue has been fixed. Can you please rebase this change to make all the checks pass? Thanks.

@ayaankhan98

ayaankhan98 commented Jul 30, 2020 •

Copy link
Copy Markdown
Contributor Author

@ayaankhan98 The issue has been fixed. Can you please rebase this change to make all the checks pass? Thanks.

@goderbauer and @Piinks , i am facing some issue with my machine therefore i am unable to rebase the commits at this time. see if anyone of you can run the checks manually.

@goderbauer

goderbauer commented Aug 5, 2020 •

Copy link
Copy Markdown
Member

@ayaankhan98 Is your machine working again? Can you try rebasing it again? We'd have to create a new PR to do the rebase.

@fluttergithubbot
fluttergithubbot merged commit 4680ff3 into flutter:master Aug 6, 2020
mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MaterialColor Swatch Map comparison always false

5 participants