32 lines
1.0 KiB
Dart
32 lines
1.0 KiB
Dart
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';
|
|
|
|
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(
|
|
attributes?.name ?? 'UNKNOWN',
|
|
imageUrl: attributes?.image ?? _imagePlaceholder,
|
|
descriptionText: _makeDescriptionText(attributes?.height, attributes?.weight),
|
|
id: id,
|
|
);
|
|
|
|
String _makeDescriptionText(String? height, String? weight) {
|
|
return height != null && weight != null
|
|
? 'Height: $height, Weight: $weight'
|
|
: height != null
|
|
? 'Height: $height'
|
|
: weight != null
|
|
? 'Weight: $weight'
|
|
: '';
|
|
}
|
|
} |