DynamicFormModel.fromJson constructor

DynamicFormModel.fromJson(
  1. Map<String, dynamic> json,
  2. Map<String, dynamic>? answers
)

Implementation

factory DynamicFormModel.fromJson(
    Map<String, dynamic> json, Map<String, dynamic>? answers) {
  var itemsJson = (json['SchemaDefinition']['items'] as List? ?? [])
      .cast<Map<String, dynamic>>();

  List<dynamic> items = []; // Can contain both FieldGroups and FieldModels

  for (var itemJson in itemsJson) {
    if (itemJson.containsKey('fieldGroup')) {
      items
          .add(FieldGroup.fromJson(itemJson['fieldGroup'], answers: answers));
    }
  }

  return DynamicFormModel(
    formId: json['Id'] as int? ?? 0,
    title: json['Name'] as String? ?? 'No Title',
    items: items,
    rawSchemaDefinition: json['SchemaDefinition'],
  );
}