实体和数据传输对象中嵌套类的flutter ddd firebase course (reso coder)问题

奥卢

我正在尝试在我的项目中使用由 reso 编码器解释的 ddd 体系结构。但是当我尝试将一个类嵌套到另一个类中以用于实体和数据传输对象时,它不起作用。我已经尝试了我所知道的一切,搜索但没有结果。

这是实体文件

    @freezed
abstract class Post implements _$Post {
  const Post._();
  const factory Post({
    required UniqueId id,
    required User author,
    required VideoUrl videoUrl,
    required Caption caption,
  }) = _Post;

  factory Post.empty() => Post(
        id: UniqueId(),
        caption: Caption(''),
        videoUrl: VideoUrl(''),
        author: User.empty(),
      );

  Option<ValueFailure<dynamic>> get failureOption {
    return caption.failureOrUnit
        .andThen(videoUrl.failureOrUnit)
        .fold((f) => some(f), (_) => none());
  }
}

这是 dto 文件

    @freezed
abstract class PostDto implements _$PostDto {
  const PostDto._();
  const factory PostDto({
    required String id,
    required UserDto author,
    required String videoUrl,
    required String caption,
    //required DateTime date,
  }) = _PostDto;

  factory PostDto.fromDomain(Post post) {
    return PostDto(
      id: post.id.getOrCrash(),
      author: ,
      videoUrl: post.videoUrl.getOrCrash(),
      caption: post.caption.getOrCrash(),
      // date: Timestamp.fromDate(date),
    );
  }

  Post toDomain() {
    return Post(
      id: UniqueId.fromUniqueString(id),
      author: ,
      caption: Caption(caption),
      videoUrl: VideoUrl(videoUrl),
    );
  }

  factory PostDto.fromJson(Map<String, dynamic> json) =>
      _$PostDtoFromJson(json);

 
}
罗伯特·桑德伯格

那么你的文件中一个明显的问题是:

author: ,

PostDto工厂和Post toDomain()方法中。

但没有进一步的细节,就更难猜测了。

如果我进一步猜测。我会说你应该有这样的东西:

author: UserDto.fromDomain(post.author),

和:

author: author.toDomain(),

当然,实现这些方法。

此外,如果您使用的是最新版本的 freezed 和 freezed_annotation,您可能会收到不再需要抽象关键字的警告。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章