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

Support for Dart 3 Interfaces #974

Closed
khari998 opened this issue Sep 7, 2023 · 3 comments
Closed

Support for Dart 3 Interfaces #974

khari998 opened this issue Sep 7, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@khari998
Copy link

khari998 commented Sep 7, 2023

I am trying to build model and entity classes using clean architecture. Previously there was no way to properly have models implement all of the characteristics of entities in a clean way. Now with the new class modifiers in Dart 3, we can use interfaces to do this easily. The problem is that Freezed fails when doing this because it is looking for a .copyWith method of the interface class.

@freezed 
interface class User with _$User {
  const factory User({
    required String id,
    required String name,
  }) = _$User;
}

@freezed 
class UserModel with _$UserModel implements User {
  const factory UserModel({
    required String id,
    required String name,
  }) = _$UserModel;

  factory UserModel.fromJson(Map<String, dynamic> json) =>
      _$UserModelFromJson(json);
}

Gives me the error:

Superinterfaces don't have a valid override for 'copyWith': _$UserModel.copyWith ($UserModelCopyWith<UserModel> Function()), _$User..copyWith ($UserCopyWith<User> Function()).
Try adding an explicit override that is consistent with all of the inherited members.
@rrousselGit
Copy link
Owner

Feel free to disable copyWith on the interface

@Freezed(copyWith: false)

@khari998
Copy link
Author

khari998 commented Sep 7, 2023

Feel free to disable copyWith on the interface

@Freezed(copyWith: false)

This worked! Thanks. It would be nice to keep copyWith functionality in the future in case it is needed but this should do for now

@rrousselGit
Copy link
Owner

Closing in favour of #975

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants