import 'package:mobilki_lab1/data/dtos/pokemon_dto.dart'; import 'package:mobilki_lab1/domain/models/card.dart'; import 'package:mobilki_lab1/domain/models/home.dart'; import 'package:flutter/material.dart'; const _imagePlaceholder = 'https://upload.wikimedia.org/wikipedia/en/archive/b/b1/20210811082420%21Portrait_placeholder.png'; extension PokemonDtoToModel on PokemonDto { HomeData toDomain() => HomeData( data: data?.map((e) => e.toDomain()).toList(), nextPage: meta?.pagination?.next, ); } extension PokemonDataDtoToModel on PokemonDataDto { CardData toDomain() => CardData( name ?? 'UNKNOWN', imageUrl: images?.small ?? _imagePlaceholder, descriptionText: _makeDescriptionText(types, evolvesTo), id: id, ); String _makeDescriptionText(List? types, List? evolvesTo) { final typeText = types != null && types.isNotEmpty ? 'Types: ${types.join(", ")}' : ''; final evolvesToText = evolvesTo != null && evolvesTo.isNotEmpty ? 'Evolves To: ${evolvesTo.join(", ")}' : ''; return '$typeText\n$evolvesToText'.trim(); } }