Discussion.fromJson constructor

Discussion.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory Discussion.fromJson(Map<String, dynamic> json) {
  final rootKey = json.keys.first;
  final rootValue = json[rootKey] as Map<String, dynamic>;
  json.remove(rootKey);

  return Discussion(
    Post.fromJson(rootValue),
    comments: json.map(
      (k, dynamic v) => MapEntry(k, Post.fromJson(v as Map<String, dynamic>)),
    ),
  );
}