fromJsonOrNull static method

FieldModel? fromJsonOrNull(
  1. Map<String, dynamic>? json
)

Constructs a new instance of FieldModel, from json, which must be a valid JSON object. Returns null if json is null or if the conversion fails.

Implementation

static FieldModel? fromJsonOrNull(
  Map<String, dynamic>? json,
) {
  try {
    final fieldPath = letListOrNull<dynamic>(json?['fieldPath'])
        ?.map(
          (p0) => p0?.toString().trim().nullIfEmpty,
        )
        .nonNulls
        .nullIfEmpty
        ?.toList();
    final fieldType = json?['fieldType'];
    final nullable = letAsOrNull<bool>(json?['nullable']);
    final children = letListOrNull<dynamic>(json?['children'])
        ?.map(
          (p0) => letMapOrNull<dynamic, dynamic>(p0)
              ?.map(
                (p0, p1) => MapEntry(
                  p0?.toString().trim().nullIfEmpty,
                  p1,
                ),
              )
              .nonNulls
              .nullIfEmpty,
        )
        .nonNulls
        .nullIfEmpty
        ?.toList();
    final primaryKey = letAsOrNull<bool>(json?['primaryKey']);
    final foreignKey = letAsOrNull<bool>(json?['foreignKey']);
    final fallback = json?['fallback'];
    final description = json?['description']?.toString().trim().nullIfEmpty;
    return FieldModel(
      fieldPath: fieldPath,
      fieldType: fieldType,
      nullable: nullable,
      children: children,
      primaryKey: primaryKey,
      foreignKey: foreignKey,
      fallback: fallback,
      description: description,
    );
  } catch (e) {
    return null;
  }
}