FieldGroup.fromJson constructor
Implementation
factory FieldGroup.fromJson(Map<String, dynamic> json,
{Map<String, dynamic>? answers}) {
var itemsJson = json['items'] as List? ?? [];
List<dynamic> items =
[]; // This will hold either FieldModel or FieldGroup instances
for (var itemJson in itemsJson) {
if (itemJson.containsKey('fieldGroup')) {
items
.add(FieldGroup.fromJson(itemJson['fieldGroup'], answers: answers));
} else {
items.add(
FieldModel.fromJson(itemJson, answer: answers?[itemJson['fId']]));
}
}
return FieldGroup(
title: json['title'] as String? ?? 'No Title',
items: items,
);
}