fromJson method

  1. @override
List<Collectible> fromJson(
  1. List? json
)

Converts JSON data to a list of Collectible instances.

Implementation

@override
List<Collectible> fromJson(List<dynamic>? json) {
  if (json == null) {
    return [];
  } else {
    return json.map(
      (e) {
        Collectible collectible = Collectible.fromJson(e);
        final Map<String, dynamic>? metadata =
            collectible.decodeDescriptorUri();
        if (collectible.name == null && metadata?['name'] != null) {
          collectible = collectible.copyWith(
            name: metadata!['name'],
          );
        }

        if (collectible.imageURL == null && metadata?['image'] != null) {
          collectible = collectible.copyWith(
            imageURL: metadata!['image'],
          );
        }

        return collectible;
      },
    ).toList();
  }
}