fromJson static method

SlideElement? fromJson(
  1. dynamic value
)

Returns a new SlideElement instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static SlideElement? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      assert(json.containsKey(r'id'), 'Required key "SlideElement[id]" is missing from JSON.');
      assert(json[r'id'] != null, 'Required key "SlideElement[id]" has a null value in JSON.');
      assert(json.containsKey(r'slideId'), 'Required key "SlideElement[slideId]" is missing from JSON.');
      assert(json[r'slideId'] != null, 'Required key "SlideElement[slideId]" has a null value in JSON.');
      assert(json.containsKey(r'elementType'), 'Required key "SlideElement[elementType]" is missing from JSON.');
      assert(json[r'elementType'] != null, 'Required key "SlideElement[elementType]" has a null value in JSON.');
      assert(json.containsKey(r'content'), 'Required key "SlideElement[content]" is missing from JSON.');
      assert(json[r'content'] != null, 'Required key "SlideElement[content]" has a null value in JSON.');
      assert(json.containsKey(r'x'), 'Required key "SlideElement[x]" is missing from JSON.');
      assert(json[r'x'] != null, 'Required key "SlideElement[x]" has a null value in JSON.');
      assert(json.containsKey(r'y'), 'Required key "SlideElement[y]" is missing from JSON.');
      assert(json[r'y'] != null, 'Required key "SlideElement[y]" has a null value in JSON.');
      assert(json.containsKey(r'width'), 'Required key "SlideElement[width]" is missing from JSON.');
      assert(json[r'width'] != null, 'Required key "SlideElement[width]" has a null value in JSON.');
      assert(json.containsKey(r'height'), 'Required key "SlideElement[height]" is missing from JSON.');
      assert(json[r'height'] != null, 'Required key "SlideElement[height]" has a null value in JSON.');
      assert(json.containsKey(r'rotation'), 'Required key "SlideElement[rotation]" is missing from JSON.');
      assert(json[r'rotation'] != null, 'Required key "SlideElement[rotation]" has a null value in JSON.');
      assert(json.containsKey(r'zIndex'), 'Required key "SlideElement[zIndex]" is missing from JSON.');
      assert(json[r'zIndex'] != null, 'Required key "SlideElement[zIndex]" has a null value in JSON.');
      assert(json.containsKey(r'createdAt'), 'Required key "SlideElement[createdAt]" is missing from JSON.');
      assert(json[r'createdAt'] != null, 'Required key "SlideElement[createdAt]" has a null value in JSON.');
      assert(json.containsKey(r'updatedAt'), 'Required key "SlideElement[updatedAt]" is missing from JSON.');
      assert(json[r'updatedAt'] != null, 'Required key "SlideElement[updatedAt]" has a null value in JSON.');
      return true;
    }());

    return SlideElement(
      id: mapValueOfType<String>(json, r'id')!,
      slideId: mapValueOfType<String>(json, r'slideId')!,
      elementType: mapValueOfType<String>(json, r'elementType')!,
      content: mapCastOfType<String, Object>(json, r'content')!,
      x: mapValueOfType<double>(json, r'x')!,
      y: mapValueOfType<double>(json, r'y')!,
      width: mapValueOfType<double>(json, r'width')!,
      height: mapValueOfType<double>(json, r'height')!,
      rotation: mapValueOfType<double>(json, r'rotation')!,
      zIndex: mapValueOfType<int>(json, r'zIndex')!,
      createdAt: mapDateTime(json, r'createdAt', r'')!,
      updatedAt: mapDateTime(json, r'updatedAt', r'')!,
    );
  }
  return null;
}