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

fix: EquatableMixin == to use Object instead of Object? #122

Merged
merged 1 commit into from Jun 14, 2021

Conversation

felangel
Copy link
Owner

Status

READY

Breaking Changes

YES (but it is considered a bug fix)

Description

Overriding == should use Object instead of Object? (revert #108) closes #115

@override
bool operator ==(Object other) {...}

@felangel felangel added the bug Something isn't working label Jun 14, 2021
@felangel felangel self-assigned this Jun 14, 2021
@felangel felangel added this to In progress in equatable Jun 14, 2021
@felangel felangel merged commit 859b195 into master Jun 14, 2021
@felangel felangel deleted the fix/equatable-mixin-equality branch June 14, 2021 21:21
Copy link
Contributor

@jeroen-meijer jeroen-meijer left a comment

Choose a reason for hiding this comment

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

Not a maintainer but, LGTM! :shipit:

@whitemagehealing
Copy link

Does this mean that Equatable currently cannot compare an object composed of mixed types (nullable and non-nullable)?

@felangel
Copy link
Owner Author

Does this mean that Equatable currently cannot compare an object composed of mixed types (nullable and non-nullable)?

That should still work:

import 'package:equatable/equatable.dart';

class CustomEquatable extends Equatable {
  const CustomEquatable(this.value);

  final String value;

  @override
  List<Object> get props => [value];
}

void main() {
  final CustomEquatable instanceA = CustomEquatable('A');
  final CustomEquatable? instanceB = CustomEquatable('A');

  print(instanceA == instanceB); // true
}

@whitemagehealing
Copy link

Thank you for the example! I managed to edit it to match my silly question and test it. :)

import 'package:equatable/equatable.dart';

class CustomEquatable extends Equatable {
  const CustomEquatable({required this.value, this.nullVal});

  final String value;
  final String? nullVal;

  @override
  List<Object?> get props => [value, nullVal];
}

void main() {
  final CustomEquatable instanceA = CustomEquatable(value: 'A');
  final CustomEquatable? instanceB = CustomEquatable(value: 'A');

  print(instanceA == instanceB); // true
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
equatable
  
In progress
Development

Successfully merging this pull request may close these issues.

Should EquatableMixin.== have Object instead of Object? as an argument?
4 participants