2024-10-29 14:36:44 +04:00
|
|
|
import 'package:flutter/material.dart';
|
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';
|
|
|
|
|
2024-10-29 14:36:44 +04:00
|
|
|
extension PokemonListDtoToModel on PokemonListDto {
|
2024-10-17 00:37:52 +04:00
|
|
|
HomeData toDomain() => HomeData(
|
2024-10-29 14:36:44 +04:00
|
|
|
data: results?.map((e) => e.toDomain()).toList(),
|
|
|
|
nextPage: next != null ? int.tryParse(next!.split('?')[1].split('=')[1]) : null,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
extension PokemonDtoToModel on PokemonDto {
|
|
|
|
CardData toDomain() => CardData(
|
|
|
|
name ?? 'UNKNOWN',
|
|
|
|
descriptionText: '', // Здесь можно добавить описание, если оно есть
|
|
|
|
imageUrl: _imagePlaceholder, // Здесь нужно добавить логику для получения URL изображения
|
|
|
|
id: null, // Здесь можно добавить логику для получения ID
|
|
|
|
icon: Icons.catching_pokemon, // Используем стандартную иконку
|
2024-10-17 00:37:52 +04:00
|
|
|
);
|
2024-10-18 21:36:44 +04:00
|
|
|
}
|
2024-10-14 21:25:43 +04:00
|
|
|
|
2024-10-29 14:36:44 +04:00
|
|
|
extension PokemonDetailsDtoToModel on PokemonDetailsDto {
|
2024-10-18 21:36:44 +04:00
|
|
|
CardData toDomain() => CardData(
|
2024-10-29 14:36:44 +04:00
|
|
|
name ?? 'UNKNOWN',
|
|
|
|
descriptionText: _makeDescriptionText(height, weight),
|
|
|
|
imageUrl: sprites?.frontDefault ?? _imagePlaceholder,
|
2024-10-18 21:36:44 +04:00
|
|
|
id: id,
|
2024-10-29 14:36:44 +04:00
|
|
|
icon: Icons.catching_pokemon, // Используем стандартную иконку
|
2024-10-17 00:37:52 +04:00
|
|
|
);
|
|
|
|
|
2024-10-29 14:36:44 +04:00
|
|
|
String _makeDescriptionText(int? height, int? weight) {
|
2024-10-18 21:36:44 +04:00
|
|
|
return height != null && weight != null
|
|
|
|
? 'Height: $height, Weight: $weight'
|
|
|
|
: height != null
|
|
|
|
? 'Height: $height'
|
|
|
|
: weight != null
|
|
|
|
? 'Weight: $weight'
|
|
|
|
: '';
|
2024-10-14 21:25:43 +04:00
|
|
|
}
|
2024-10-17 00:37:52 +04:00
|
|
|
}
|