felangel / equatable

A Dart package that helps to implement value based equality without needing to explicitly override == and hashCode.

Home Page:https://pub.dev/packages/equatable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is that logical? Object equals but element not equals.

FantaZZ opened this issue · comments

import 'package:equatable/equatable.dart';

class Person extends Equatable {
  final String name;
  final List<Card> cards;

  const Person({
    required this.name,
    required this.cards,
  });

  @override
  List<Object> get props => [name, cards];
}

// ** not @immutable **
class Card extends Equatable {
  String name;

  Card({
    required this.name,
  });

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

main() {
  List<Card> cards = [Card(name: 'visa')];
  Person jax = Person(name: 'jax', cards: cards);

  List<Card> cardsCopy = [...cards];
  cardsCopy[0].name = 'mastercard';

  Person jaxCopy = Person(name: 'jax', cards: cardsCopy);

  print(cards == cardsCopy); // false
  print(jax == jaxCopy); // true
}

Oh I got point