что то добавила
This commit is contained in:
parent
5ccdd70494
commit
f84c163686
@ -31,3 +31,36 @@ class PokemonDataDto {
|
|||||||
|
|
||||||
factory PokemonDataDto.fromJson(Map<String, dynamic> json) => _$PokemonDataDtoFromJson(json);
|
factory PokemonDataDto.fromJson(Map<String, dynamic> json) => _$PokemonDataDtoFromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonSerializable(createToJson: false)
|
||||||
|
class PokemonDetailsDto {
|
||||||
|
final int? height;
|
||||||
|
final int? weight;
|
||||||
|
final List<AbilityDto>? abilities;
|
||||||
|
|
||||||
|
const PokemonDetailsDto({
|
||||||
|
this.height,
|
||||||
|
this.weight,
|
||||||
|
this.abilities,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory PokemonDetailsDto.fromJson(Map<String, dynamic> json) => _$PokemonDetailsDtoFromJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSerializable(createToJson: false)
|
||||||
|
class AbilityDto {
|
||||||
|
final AbilityDetailDto? ability;
|
||||||
|
|
||||||
|
const AbilityDto({this.ability});
|
||||||
|
|
||||||
|
factory AbilityDto.fromJson(Map<String, dynamic> json) => _$AbilityDtoFromJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSerializable(createToJson: false)
|
||||||
|
class AbilityDetailDto {
|
||||||
|
final String? name;
|
||||||
|
|
||||||
|
const AbilityDetailDto({this.name});
|
||||||
|
|
||||||
|
factory AbilityDetailDto.fromJson(Map<String, dynamic> json) => _$AbilityDetailDtoFromJson(json);
|
||||||
|
}
|
@ -1,22 +0,0 @@
|
|||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
||||||
|
|
||||||
part of 'pokemon_dto.dart';
|
|
||||||
|
|
||||||
// **************************************************************************
|
|
||||||
// JsonSerializableGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
PokemonDto _$PokemonDtoFromJson(Map<String, dynamic> json) => PokemonDto(
|
|
||||||
results: (json['results'] as List<dynamic>?)
|
|
||||||
?.map((e) => PokemonDataDto.fromJson(e as Map<String, dynamic>))
|
|
||||||
.toList(),
|
|
||||||
count: (json['count'] as num?)?.toInt(),
|
|
||||||
next: json['next'] as String?,
|
|
||||||
previous: json['previous'] as String?,
|
|
||||||
);
|
|
||||||
|
|
||||||
PokemonDataDto _$PokemonDataDtoFromJson(Map<String, dynamic> json) =>
|
|
||||||
PokemonDataDto(
|
|
||||||
name: json['name'] as String?,
|
|
||||||
url: json['url'] as String?,
|
|
||||||
);
|
|
@ -25,3 +25,10 @@ extension PokemonDataDtoToModel on PokemonDataDto {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension PokemonDetailsDtoToModel on PokemonDetailsDto {
|
||||||
|
String toDescriptionText() {
|
||||||
|
final abilitiesText = abilities?.map((ability) => ability.ability?.name ?? 'UNKNOWN').join(', ') ?? 'UNKNOWN';
|
||||||
|
return 'Height: ${height ?? 'UNKNOWN'} cm, Weight: ${weight ?? 'UNKNOWN'} kg, Abilities: $abilitiesText';
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user