Skip to content

MaterialColor Swatch Map comparison always false #61888

Closed

Description

@georgiossalon

I am using a Dropdown of type myObject.

myObject contains a MaterialColor parameter. For the comparison of these objects, I am using the Equatable library.

At some point in the comparison, the code jumps into the colors.dart file at the following line:

The error occurs since _swatch is a Map and the comparison other._swatch == _swatch; will always return false if the Maps have different hashCodes.

The == should probably get replaced by MapEquality().equals(other._swatch,_swatch)

Activity

  1. ayaankhan98 commented on Jul 20, 2020

    @ayaankhan98
    Contributor

    @georgiossalon can i work on this?

  2. added
    p: material_uimaterial_ui package in flutter/packages
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Jul 20, 2020
  3. georgiossalon commented on Jul 21, 2020

    @georgiossalon
    Author

    @ayaankhan98 Sure why not. Do you need something from me?

  4. changed the title [-]MaterialColor Swatch Comparison Bug[/-] [+]MaterialColor Swatch Map comparison always false[/+] on Jul 21, 2020
  5. markusaksli-nc commented on Jul 21, 2020

    @markusaksli-nc
    Contributor

    Reproducible on the latest master 1.21.0-2.0.pre.83.

    Minimal reproducible sample 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());
    }
    
    flutter doctor -v
    [√] Flutter (Channel master, 1.21.0-2.0.pre.83, on Microsoft Windows [Version 10.0.18362.900], locale et-EE)
       • Flutter version 1.21.0-2.0.pre.83 at C:\Development\flutter_master
       • Framework revision 9e658bc3d5 (7 hours ago), 2020-07-21 03:56:07 +0200
       • Engine revision dcc9a4048d
       • Dart version 2.9.0 (build 2.9.0-21.0.dev 9dca49e71e)
    
    [√] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
       • Android SDK at C:\Users\Isa\AppData\Local\Android\sdk
       • Platform android-30, build-tools 30.0.0
       • Java binary at: C:\Users\Isa\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\193.6626763\jre\bin\java
       • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
       • All Android licenses accepted.
    
    [√] Chrome - develop for the web
       • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
    
    [√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.6.4)
       • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
       • Visual Studio Community 2019 version 16.6.30309.148
       • Windows 10 SDK version 10.0.18362.0
    
    [√] Android Studio (version 4.0)
       • Android Studio at C:\Users\Isa\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\193.6626763
       • Flutter plugin version 47.1.2
       • Dart plugin version 193.7361
       • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    
    [√] VS Code (version 1.47.2)
       • VS Code at C:\Users\Isa\AppData\Local\Programs\Microsoft VS Code
       • Flutter extension version 3.12.2
    
    [√] Connected device (4 available)
       • sdk gphone x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
       • Windows (desktop)       • windows       • windows-x64    • Microsoft Windows [Version 10.0.18362.900]
       • Web Server (web)        • web-server    • web-javascript • Flutter Tools
       • Chrome (web)            • chrome        • web-javascript • Google Chrome 84.0.4147.89
    
    • No issues found!
    
  6. ayaankhan98 commented on Jul 21, 2020

    @ayaankhan98
    Contributor

    @ayaankhan98 Sure why not. Do you need something from me?

    @georgiossalon Thanks, i am a new contributor to flutter, i will let you know if i need any help.

    @markusaksli-nc Thanks for providing the sample reproducible code.

  7. github-actions commented on Aug 18, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  8. locked as resolved and limited conversation to collaborators on Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    found in release: 1.21Found to occur in 1.21frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packages

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions