fromJsonOrNull static method

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

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

Implementation

static GenerateDartModel? fromJsonOrNull(
  Map<String, dynamic>? json,
) {
  try {
    final className = json?['className']?.toString().trim().nullIfEmpty;
    final fields = letSetOrNull<dynamic>(json?['fields'])
        ?.map(
          (p0) => p0,
        )
        .nonNulls
        .nullIfEmpty
        ?.toSet()
        .unmodifiable;
    final shouldInherit = letBoolOrNull(json?['shouldInherit']);
    final inheritanceConstructor =
        json?['inheritanceConstructor']?.toString().trim().nullIfEmpty;
    final keyStringCase =
        json?['keyStringCase']?.toString().trim().nullIfEmpty;
    final description = json?['description']?.toString().trim().nullIfEmpty;
    final tableName = json?['tableName']?.toString().trim().nullIfEmpty;
    final schema = json?['schema']?.toString().trim().nullIfEmpty;
    final indexes = letListOrNull<dynamic>(json?['indexes'])
        ?.map(
          (p0) => letMapOrNull<dynamic, dynamic>(p0)
              ?.map(
                (p0, p1) => MapEntry(
                  p0?.toString().trim().nullIfEmpty,
                  p1,
                ),
              )
              .nonNulls
              .nullIfEmpty
              ?.unmodifiable,
        )
        .nonNulls
        .nullIfEmpty
        ?.toList()
        .unmodifiable;
    return GenerateDartModel(
      className: className,
      fields: fields,
      shouldInherit: shouldInherit,
      inheritanceConstructor: inheritanceConstructor,
      keyStringCase: keyStringCase,
      description: description,
      tableName: tableName,
      schema: schema,
      indexes: indexes,
    );
  } catch (e) {
    return null;
  }
}