fromJsonOrNull static method

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

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

Implementation

static ReferencedModel? fromJsonOrNull(
  Map<String, dynamic>? json,
) {
  try {
    final id = json?['id']?.toString().trim().nullIfEmpty;
    final ref = () {
      final a = letMapOrNull<String, dynamic>(json?['ref']);
      return a != null ? DataRefModel.fromJson(a) : null;
    }();
    return ReferencedModel(
      id: id,
      ref: ref,
    );
  } catch (e) {
    return null;
  }
}