I'm trying to programme to an interface with Freezed. I want to be able to specify all over my app, the type IUserRegistrationEntity;
My interface:
abstract class IUserRegistrationEntity {
String nickName;
String email;
String confirmEmail;
String password;
String confirmPassword;
}
My freezed class:
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:vepo/domain/user_registration/i_user_registration_entity.dart';
part 'user_registration_entity.freezed.dart';
@freezed
abstract class UserRegistrationEntity with _$UserRegistrationEntity {
@Implements(IUserRegistrationEntity)
factory UserRegistrationEntity(
{String nickName,
String email,
String confirmEmail,
String password,
String confirmPassword}) = _UserRegistrationEntity;
}
Getting the error when running the app:
lib/domain/user_registration/user_registration_entity.freezed.dart:165:7: Error: The non-abstract class '_$_UserRegistrationEntity' is missing implementations for these members:
- IUserRegistrationEntity.confirmEmail
- IUserRegistrationEntity.confirmPassword
- IUserRegistrationEntity.email
- IUserRegistrationEntity.nickName
- IUserRegistrationEntity.password
Try to either
- provide an implementation,
- inherit an implementation from a superclass or mixin,
- mark the class as abstract, or
- provide a 'noSuchMethod' implementation.
class _$_UserRegistrationEntity implements _UserRegistrationEntity {
^^^^^^^^^^^^^^^^^^^^^^^^^
lib/domain/user_registration/i_user_registration_entity.dart:4:10: Context: 'IUserRegistrationEntity.confirmEmail' is defined here.
String confirmEmail;
^^^^^^^^^^^^
lib/domain/user_registration/i_user_registration_entity.dart:6:10: Context: 'IUserRegistrationEntity.confirmPassword' is defined here.
String confirmPassword;
^^^^^^^^^^^^^^^
lib/domain/user_registration/i_user_registration_entity.dart:3:10: Context: 'IUserRegistrationEntity.email' is defined here.
String email;
^^^^^
lib/domain/user_registration/i_user_registration_entity.dart:2:10: Context: 'IUserRegistrationEntity.nickName' is defined here.
String nickName;
^^^^^^^^
lib/domain/user_registration/i_user_registration_entity.dart:5:10: Context: 'IUserRegistrationEntity.password' is defined here.
String password;
^^^^^^^^
What am I doing wrong?
Edit: Does this quote from the package docs mean it is not possible?.
Note 2: You cannot use @With/@Implements with freezed classes. Freezed classes can neither be extended nor implemented.
Keen to know if people think this is a drawback if so.
I tested out your code and found the problem from the generated file. Thing is, freezed doesn't override setters from the implemented abstract class. So, for your
IUserRegistrationEntity, make the parameters as getters. Like so: