6

I'm quite new to Flutter (and even more to the Freezed package...) So I hope that the question is relevant.

So, here is my usecase: a User can be Member of differents groups. A User class shares . I have issues to deal with this relationship with Freezed:

@freezed
abstract class User with _$User {
  const factory User({
    @required UniqueId id,
    Name firstname,
    Name lastname,
    @required EmailAddress email,
    @required bool emailVerified,
  }) = _User;
}

@freezed
abstract class Member extends User with _$Member { // Here is the issue
  const factory Member({
    @required UniqueId id,
    @required Name displayname,
    String photo,
    List roles,
    String status,
    DateTime expiration,
  }) = _Member;

_$Member.copyWith' ('$MemberCopyWith Function()') isn't a valid override of '_$User.copyWith' ('$UserCopyWith Function()').

What would be the right way to do so?

Yako
  • 3,405
  • 9
  • 41
  • 71

1 Answers1

-1

You'll have to use the Implements tag and make User a normal abstract class. But considering your scenario, I think it's best to do the following.

abstract class UserBase {
  UniqueId get id;
  Name get firstname;
  Name get lastname;
  EmailAddress get email;
  bool get emailVerified;
}

@freezed
abstract class User with _$User {
  @Implements(UserBase)
  const factory User({
    @required UniqueId id,
    Name firstname,
    Name lastname,
    @required EmailAddress email,
    @required bool emailVerified,
  }) = _User;
}

@freezed
abstract class Member with _$Member {
  @Implements(UserBase)
  const factory Member({
    @required UniqueId id,
    Name firstname,
    Name lastname,
    @required EmailAddress email,
    @required bool emailVerified,
    @required Name displayname,
    String photo,
    List roles,
    String status,
    DateTime expiration,
  }) = _Member;
}

Feel free to ask any queries.

rkdupr0n
  • 691
  • 6
  • 18
  • I'm having troubles trying to inherit a method from a parent class using Freezed. This doesn't help me with that, do you have any suggestion? – Luis Utrera Feb 18 '21 at 14:34
  • @LuisUtrera Idk exactly what your trouble is. Maybe this could help? https://stackoverflow.com/a/65264172/11566145 – rkdupr0n Feb 19 '21 at 07:27