Hi @rrousselGit
* Inherit from a freezed data class into another freezed data class*
What I have is a base FileModel like below:
@freezed
abstract class FileModel with _$FileModel {
const factory FileModel({
@required int type,
@required int size,
@required int pk,
}) = _FileModel;
factory FileModel.fromJson(Map<String, dynamic> json) =>
_$FileModelFromJson(json);
}
and then I have some classes which inherit FileModel fields like:
@freezed
abstract class CommentFileModel with _$CommentFileModel {
const factory CommentFileModel({
@required String resourcetype,
@required DateTime createdAt,
@required String blurHash,
@required int duration,
@required String title,
@required String link,
}) = _CommentFileModel;
factory CommentFileModel.fromJson(Map<String, dynamic> json) =>
_$CommentFileModelFromJson(json);
}
now, I want to know how it is possible to inherit from a freezed data class into another freezed data class.
(CommentFileModel from FileModel)
Thanks.
You cannot use Inheritance for Freezed classes.
so, I have to use normal dart class ?
You can use composition
Make CustomFileModel receive a FileModel in its constructor