【发布时间】:2021-05-11 09:53:02
【问题描述】:
我有一个看起来像这样的冻结类:
@freezed
abstract class GiftGiver with _$GiftGiver {
const factory GiftGiver({
String? id,
String? uid,
String? imageUrl,
String? giftDetails,
String? listingDate,
@Default(5) int listingFor,
Timestamp? pickUpTime,
@Default(false) canLeaveOutside,
}) = _GiftGiver;
factory GiftGiver.fromJson(Map<String, dynamic> json) =>
_$GiftGiverFromJson(json);
}
冻结的类生成正常,但 .g.dart 类没有生成,因为我有 Timestamp 类型。我在https://github.com/rrousselGit/freezed#fromjson---classes-with-multiple-constructors 看到了一些解决方案,但我不明白如何应用它来解决我的问题。
【问题讨论】:
-
能否提供时间戳的代码?它有自己的“fromJson”方法吗?这是必需的
-
时间戳是默认的 Firebase 类。我在课堂上看了看,没有 toJson 和 fromJson。但我找到了使用 JsonKey 注释的解决方案。
-
啊我明白了。在这种情况下,这是正确的解决方案,干得好