PMU-PIbd-32-Fedorenko-G-Y/flutter_app/lib/data/mappers/characters_mapper.dart

32 lines
1.0 KiB
Dart

import 'package:flutter_app/data/dtos/thrones_character_dto.dart';
import 'package:flutter_app/domain/models/card.dart';
import 'package:flutter_app/domain/models/home.dart';
const _imagePlaceholder =
'https://upload.wikimedia.org/wikipedia/en/archive/b/b1/20210811082420%21Portrait_placeholder.png';
extension ThronesCharacterDtoToModel on ThronesCharacterDto {
CardData toDomain() => CardData(
descriptionText: _makeDescriptionText(title, family),
firstName: firstName,
lastName: lastName,
title: title,
family: family,
fullName: fullName,
imageUrl: imageUrl,
text: '',
speciesText: species ?? 'unknown',
locationText: location?.name ?? 'unknown',
);
String _makeDescriptionText(String? title, String? family) {
return title != null && family != null
? '$title of $family'
: title != null
? 'Title: $title'
: family != null
? 'Family: $family'
: '';
}
}