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

69 lines
1.5 KiB
Dart

import 'package:json_annotation/json_annotation.dart';
part 'pokemon_dto.g.dart';
@JsonSerializable(createToJson: false)
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,
});
factory PokemonListDto.fromJson(Map<String, dynamic> json) => _$PokemonListDtoFromJson(json);
}
@JsonSerializable(createToJson: false)
class PokemonDto {
final String? name;
final String? url;
const PokemonDto({this.name, this.url});
factory PokemonDto.fromJson(Map<String, dynamic> json) => _$PokemonDtoFromJson(json);
}
@JsonSerializable(createToJson: false)
class PokemonDetailsDto {
@JsonKey(fromJson: _idFromJson)
final String? id;
final String? name;
final int? height;
final int? weight;
final SpritesDto? sprites;
const PokemonDetailsDto({
this.id,
this.name,
this.height,
this.weight,
this.sprites,
});
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;
}
}
}
@JsonSerializable(createToJson: false)
class SpritesDto {
final String? frontDefault;
const SpritesDto({this.frontDefault});
factory SpritesDto.fromJson(Map<String, dynamic> json) => _$SpritesDtoFromJson(json);
}