fromJson static method

Attachment? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static Attachment? 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(() {
      requiredKeys.forEach((key) {
        assert(json.containsKey(key), 'Required key "Attachment[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "Attachment[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return Attachment(
      actions: Action.listFromJson(json[r'actions']),
      assetUrl: mapValueOfType<String>(json, r'asset_url'),
      authorIcon: mapValueOfType<String>(json, r'author_icon'),
      authorLink: mapValueOfType<String>(json, r'author_link'),
      authorName: mapValueOfType<String>(json, r'author_name'),
      color: mapValueOfType<String>(json, r'color'),
      custom: mapCastOfType<String, Object>(json, r'custom')!,
      fallback: mapValueOfType<String>(json, r'fallback'),
      fields: Field.listFromJson(json[r'fields']),
      footer: mapValueOfType<String>(json, r'footer'),
      footerIcon: mapValueOfType<String>(json, r'footer_icon'),
      giphy: Images.fromJson(json[r'giphy']),
      imageUrl: mapValueOfType<String>(json, r'image_url'),
      ogScrapeUrl: mapValueOfType<String>(json, r'og_scrape_url'),
      originalHeight: mapValueOfType<int>(json, r'original_height'),
      originalWidth: mapValueOfType<int>(json, r'original_width'),
      pretext: mapValueOfType<String>(json, r'pretext'),
      text: mapValueOfType<String>(json, r'text'),
      thumbUrl: mapValueOfType<String>(json, r'thumb_url'),
      title: mapValueOfType<String>(json, r'title'),
      titleLink: mapValueOfType<String>(json, r'title_link'),
      type: mapValueOfType<String>(json, r'type'),
    );
  }
  return null;
}