2024-10-14 21:25:43 +04:00
|
|
|
import 'package:mobilki_lab1/data/dtos/pokemon_dto.dart';
|
|
|
|
import 'package:mobilki_lab1/domain/models/card.dart';
|
2024-10-17 00:37:52 +04:00
|
|
|
import 'package:mobilki_lab1/domain/models/home.dart';
|
2024-10-14 21:25:43 +04:00
|
|
|
|
|
|
|
const _imagePlaceholder =
|
|
|
|
'https://upload.wikimedia.org/wikipedia/en/archive/b/b1/20210811082420%21Portrait_placeholder.png';
|
|
|
|
|
|
|
|
extension PokemonDtoToModel on PokemonDto {
|
2024-10-17 00:37:52 +04:00
|
|
|
HomeData toDomain() => HomeData(
|
|
|
|
data: [toCardData()],
|
|
|
|
nextPage: null,
|
|
|
|
);
|
2024-10-14 21:25:43 +04:00
|
|
|
|
2024-10-17 00:37:52 +04:00
|
|
|
CardData toCardData() => CardData(
|
|
|
|
name ?? 'UNKNOWN',
|
|
|
|
descriptionText: _makeDescriptionText(types, abilities),
|
|
|
|
imageUrl: sprites?.front_default ?? _imagePlaceholder,
|
|
|
|
);
|
|
|
|
|
|
|
|
String _makeDescriptionText(List<PokemonTypeDto>? types, List<PokemonAbilityDto>? abilities) {
|
|
|
|
final typeNames = types?.map((e) => e.type?.name).whereType<String>().join(', ') ?? '';
|
|
|
|
final abilityNames = abilities?.map((e) => e.ability?.name).whereType<String>().join(', ') ?? '';
|
|
|
|
return 'Types: $typeNames\nAbilities: $abilityNames';
|
2024-10-14 21:25:43 +04:00
|
|
|
}
|
2024-10-17 00:37:52 +04:00
|
|
|
}
|