[Flutter] Equatable 패키지?

kimdocs...📄·2023년 11월 27일
0

flutter

목록 보기
13/30

설치

flutter pub add equatable

→ pubspec.yaml 파일에서 설치 되었는 지 확인 가능함

Equatable 패키지가 필요한 이유

operator == 과 hashcode 메소드를 정의해주어야하는데, equatable라이브러리를 통해 더 쉽게 사용이 가능하다.

사용 방법

class Person extends Equatable {
  final int id;
  final String name;
  final int age;

  Person({
    required this.id,
    required this.name,
    required this.age,
  });

  
  List<Object> get props => [this.id, this.name, this.age];
}
  • Equatable를 상속받고 List get props를 overriding해주면 된다.
profile
👩‍🌾 GitHub: ezidayzi / 📂 Contact: ezidayzi@gmail.com

0개의 댓글