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-11-16 13:37:18 +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-11-16 13:37:18 +04:00
|
|
|
HomeData toDomain() => HomeData(
|
|
|
|
data: results?.map((e) => e.toDomain()).toList(),
|
|
|
|
nextPage: next != null ? int.tryParse(next!.split('=')[1].split('&')[0]) : null,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
extension PokemonDataDtoToModel on PokemonDataDto {
|
|
|
|
CardData toDomain() {
|
|
|
|
final id = url?.split('/')[6] ?? 'UNKNOWN';
|
|
|
|
final imageUrl = 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/$id.png';
|
2024-10-14 21:25:43 +04:00
|
|
|
|
2024-11-16 13:37:18 +04:00
|
|
|
return CardData(
|
|
|
|
name ?? 'UNKNOWN',
|
|
|
|
imageUrl: imageUrl,
|
|
|
|
descriptionText: 'ID: $id',
|
|
|
|
id: id,
|
|
|
|
);
|
2024-10-14 21:25:43 +04:00
|
|
|
}
|
2024-10-16 23:18:15 +04:00
|
|
|
}
|
2024-11-16 13:37:18 +04:00
|
|
|
|
|
|
|
extension PokemonDetailsDtoToModel on PokemonDetailsDto {
|
|
|
|
String toDescriptionText() {
|
|
|
|
final abilitiesText = abilities?.map((ability) => ability.ability?.name ?? 'UNKNOWN').join(', ') ?? 'UNKNOWN';
|
|
|
|
return 'Height: ${height ?? 'UNKNOWN'} cm, Weight: ${weight ?? 'UNKNOWN'} kg, Abilities: $abilitiesText';
|
|
|
|
}
|
|
|
|
}
|