PIbd-32_Chubykina_P.P._mobilki/lib/data/dtos/pokemon_dto.dart

69 lines
1.5 KiB
Dart
Raw Normal View History

2024-10-14 21:25:43 +04:00
import 'package:json_annotation/json_annotation.dart';
part 'pokemon_dto.g.dart';
@JsonSerializable(createToJson: false)
2024-10-29 14:36:44 +04:00
class PokemonListDto {
final int? count;
final String? next;
final String? previous;
final List<PokemonDto>? results;
const PokemonListDto({
this.count,
this.next,
this.previous,
this.results,
2024-10-14 21:25:43 +04:00
});
2024-10-29 14:36:44 +04:00
factory PokemonListDto.fromJson(Map<String, dynamic> json) => _$PokemonListDtoFromJson(json);
2024-10-14 21:25:43 +04:00
}
@JsonSerializable(createToJson: false)
2024-10-29 14:36:44 +04:00
class PokemonDto {
final String? name;
final String? url;
2024-10-14 21:25:43 +04:00
2024-10-29 14:36:44 +04:00
const PokemonDto({this.name, this.url});
2024-10-14 21:25:43 +04:00
2024-10-29 14:36:44 +04:00
factory PokemonDto.fromJson(Map<String, dynamic> json) => _$PokemonDtoFromJson(json);
2024-10-14 21:25:43 +04:00
}
@JsonSerializable(createToJson: false)
2024-10-29 14:36:44 +04:00
class PokemonDetailsDto {
@JsonKey(fromJson: _idFromJson)
final String? id;
final String? name;
2024-10-29 14:36:44 +04:00
final int? height;
final int? weight;
final SpritesDto? sprites;
2024-10-29 14:36:44 +04:00
const PokemonDetailsDto({
this.id,
2024-10-18 21:36:44 +04:00
this.name,
this.height,
this.weight,
2024-10-29 14:36:44 +04:00
this.sprites,
2024-10-18 21:36:44 +04:00
});
2024-10-14 21:25:43 +04:00
2024-10-29 14:36:44 +04:00
factory PokemonDetailsDto.fromJson(Map<String, dynamic> json) => _$PokemonDetailsDtoFromJson(json);
static String? _idFromJson(dynamic id) {
if (id is int) {
return id.toString();
} else if (id is String) {
return id;
} else {
return null;
}
}
2024-10-14 21:25:43 +04:00
}
@JsonSerializable(createToJson: false)
2024-10-29 14:36:44 +04:00
class SpritesDto {
final String? frontDefault;
2024-10-14 21:25:43 +04:00
2024-10-29 14:36:44 +04:00
const SpritesDto({this.frontDefault});
2024-10-14 21:25:43 +04:00
2024-10-29 14:36:44 +04:00
factory SpritesDto.fromJson(Map<String, dynamic> json) => _$SpritesDtoFromJson(json);
}