GiphyAsset.fromJson constructor

GiphyAsset.fromJson(
  1. Map<Object?, Object?> json
)

Creates a GiphyAsset instance from a JSON map.

Parses the 'width' and 'height' fields, defaulting to 0 if they are missing or invalid.

Implementation

factory GiphyAsset.fromJson(Map<Object?, Object?> json) {
  return GiphyAsset(
    width: (json['width'] is String)
        ? int.tryParse(json['width'] as String? ?? "0") ?? 0
        : (json['width'] as int?) ?? 0,
    height: (json['height'] is String)
        ? int.tryParse(json['height'] as String? ?? "0") ?? 0
        : (json['height'] as int?) ?? 0,
    url: json['url'] as String?,
    format: json['format'] as String?,
  );
}