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? results; const PokemonListDto({ this.count, this.next, this.previous, this.results, }); factory PokemonListDto.fromJson(Map json) => _$PokemonListDtoFromJson(json); } @JsonSerializable(createToJson: false) class PokemonDto { final String? name; final String? url; const PokemonDto({this.name, this.url}); factory PokemonDto.fromJson(Map 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 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 json) => _$SpritesDtoFromJson(json); }