30 lines
999 B
Dart
30 lines
999 B
Dart
import '../../domain/models/card.dart';
|
|
import '../../domain/models/home.dart';
|
|
import '../dtos/characters_dto.dart';
|
|
|
|
extension CharactersDtoToModel on CharactersDto {
|
|
HomeData toDomain() => HomeData(
|
|
data: data?.map((e) => e.toDomain()).toList(),
|
|
nextPage: meta?.pagination?.next,
|
|
);
|
|
}
|
|
|
|
extension CharacterDataDtoToModel on CharacterDataDto {
|
|
CardData toDomain() => CardData(
|
|
attributes?.name ?? 'UNKNOWN',
|
|
image: attributes?.image ??
|
|
'https://upload.wikimedia.org/wikipedia/en/archive/b/b1/20210811082420%21Portrait_placeholder.png',
|
|
descriptionText: _makeDescriptionText(attributes?.nationality, attributes?.species),
|
|
id: id,
|
|
);
|
|
|
|
String _makeDescriptionText(String? nationality, String? species) {
|
|
return nationality != null && species != null
|
|
? 'Nationality - $nationality \nSpecies - $species'
|
|
: nationality != null
|
|
? 'Nationality - $nationality'
|
|
: species != null
|
|
? 'Species - $species'
|
|
: '';
|
|
}
|
|
} |