комит перед тем как все поломаю

This commit is contained in:
Полина Чубыкина 2024-11-18 16:28:59 +04:00
parent f49a119d5c
commit 20171525ce
3 changed files with 44 additions and 8 deletions

View File

@ -27,6 +27,7 @@ class PokemonDataDto {
final int? height; final int? height;
final int? weight; final int? weight;
final List<AbilityDto>? abilities; final List<AbilityDto>? abilities;
// final PokemonAttributesDataDto? attributes;
const PokemonDataDto({ const PokemonDataDto({
this.name, this.name,
@ -35,11 +36,31 @@ class PokemonDataDto {
this.height, this.height,
this.weight, this.weight,
this.abilities, this.abilities,
// this.attributes,
}); });
factory PokemonDataDto.fromJson(Map<String, dynamic> json) => _$PokemonDataDtoFromJson(json); factory PokemonDataDto.fromJson(Map<String, dynamic> json) => _$PokemonDataDtoFromJson(json);
} }
// @JsonSerializable(createToJson: false)
// class PokemonAttributesDataDto {
// final String? imageUrl;
// final int? height;
// final int? weight;
// final List<AbilityDto>? abilities;
// final PokemonSpritesDto? sprites;
//
// const PokemonAttributesDataDto({
// this.imageUrl,
// this.height,
// this.weight,
// this.abilities,
// this.sprites,
// });
//
// factory PokemonAttributesDataDto.fromJson(Map<String, dynamic> json) => _$PokemonAttributesDataDtoFromJson(json);
// }
@JsonSerializable(createToJson: false) @JsonSerializable(createToJson: false)
class AbilityDto { class AbilityDto {
final AbilityDetailDto? ability; final AbilityDetailDto? ability;
@ -57,3 +78,14 @@ class AbilityDetailDto {
factory AbilityDetailDto.fromJson(Map<String, dynamic> json) => _$AbilityDetailDtoFromJson(json); factory AbilityDetailDto.fromJson(Map<String, dynamic> json) => _$AbilityDetailDtoFromJson(json);
} }
// @JsonSerializable(createToJson: false)
// class PokemonSpritesDto {
// final String front_default;
//
// const PokemonSpritesDto({
// required this.front_default,
// });
//
// factory PokemonSpritesDto.fromJson(Map<String, dynamic> json) => _$PokemonSpritesDtoFromJson(json);
// }

View File

@ -17,6 +17,8 @@ extension PokemonDataDtoToModel on PokemonDataDto {
name ?? 'UNKNOWN', name ?? 'UNKNOWN',
imageUrl: imageUrl ?? _imagePlaceholder, imageUrl: imageUrl ?? _imagePlaceholder,
descriptionText: 'Height: ${height ?? 'UNKNOWN'} cm, Weight: ${weight ?? 'UNKNOWN'} g, Abilities: ${abilities?.map((ability) => ability.ability?.name ?? 'UNKNOWN').join(', ') ?? 'UNKNOWN'}', descriptionText: 'Height: ${height ?? 'UNKNOWN'} cm, Weight: ${weight ?? 'UNKNOWN'} g, Abilities: ${abilities?.map((ability) => ability.ability?.name ?? 'UNKNOWN').join(', ') ?? 'UNKNOWN'}',
// imageUrl: attributes?.sprites?.front_default ?? _imagePlaceholder,
// descriptionText: 'Height: ${attributes?.height ?? 'UNKNOWN'} cm, Weight: ${attributes?.weight ?? 'UNKNOWN'} g, Abilities: ${attributes?.abilities?.map((ability) => ability.ability?.name ?? 'UNKNOWN').join(', ') ?? 'UNKNOWN'}',
id: url?.split('/')[6] ?? 'UNKNOWN', id: url?.split('/')[6] ?? 'UNKNOWN',
); );
} }

View File

@ -29,19 +29,21 @@ class PokeRepository extends ApiInterface {
'limit': pageSize, 'limit': pageSize,
}; };
if (q != null && q.isNotEmpty) { // if (q != null && q.isNotEmpty) {
url = '$_baseUrl/pokemon/$q'; // url = '$_baseUrl/pokemon/$q';
queryParameters = { // queryParameters = {
'offset': page, // 'offset': page,
'limit': pageSize, // 'limit': pageSize,
}; // };
} // }
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>( final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(
url, url,
queryParameters: queryParameters, queryParameters: queryParameters,
); );
// final PokemonDto dto = PokemonDto.fromJson(response.data as Map<String, dynamic>);
// final HomeData data = dto.toDomain();
final PokemonDto dto = PokemonDto.fromJson(response.data as Map<String, dynamic>); final PokemonDto dto = PokemonDto.fromJson(response.data as Map<String, dynamic>);
final List<PokemonDataDto> pokemonDataList = dto.results ?? []; final List<PokemonDataDto> pokemonDataList = dto.results ?? [];