fromJson static method

BlockContent? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static BlockContent? 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(() {
      return true;
    }());

    return BlockContent(
      richText: RichTextObject.listFromJson(json[r'rich_text']),
      language: mapValueOfType<String>(json, r'language'),
      checked: mapValueOfType<bool>(json, r'checked'),
      icon: mapValueOfType<String>(json, r'icon'),
      color: mapValueOfType<String>(json, r'color'),
      url: mapValueOfType<String>(json, r'url'),
      caption: mapValueOfType<String>(json, r'caption'),
      altText: mapValueOfType<String>(json, r'alt_text'),
      embedUrl: mapValueOfType<String>(json, r'embed_url'),
      cells: json[r'cells'] is List
        ? (json[r'cells'] as List).map((e) =>
            RichTextObject.listFromJson(json[r'cells'])
          ).toList()
        :  const [],
      expression: mapValueOfType<String>(json, r'expression'),
    );
  }
  return null;
}