Advertisement
Dwitio

pokemon.dart

Aug 18th, 2022
1,162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.22 KB | None | 0 0
  1. class PokeHub {
  2.   List<Pokemon>? pokemon;
  3.  
  4.   PokeHub({this.pokemon});
  5.  
  6.   PokeHub.fromJson(Map<String, dynamic> json) {
  7.     if (json['pokemon'] != null) {
  8.       pokemon = <Pokemon>[];
  9.       json['pokemon'].forEach((v) {
  10.         pokemon!.add(new Pokemon.fromJson(v));
  11.       });
  12.     }
  13.   }
  14.  
  15.   Map<String, dynamic> toJson() {
  16.     final Map<String, dynamic> data = new Map<String, dynamic>();
  17.     if (this.pokemon != null) {
  18.       data['pokemon'] = this.pokemon!.map((v) => v.toJson()).toList();
  19.     }
  20.     return data;
  21.   }
  22. }
  23.  
  24. class Pokemon {
  25.   int? id;
  26.   String? num;
  27.   String? name;
  28.   String? img;
  29.   List<String>? type;
  30.   String? height;
  31.   String? weight;
  32.   String? candy;
  33.   int? candyCount;
  34.   String? egg;
  35.   String? spawnChance;
  36.   String? avgSpawns;
  37.   String? spawnTime;
  38.   List<double>? multipliers;
  39.   List<String>? weaknesses;
  40.   List<NextEvolution>? nextEvolution;
  41.  
  42.   Pokemon(
  43.       {this.id,
  44.         this.num,
  45.         this.name,
  46.         this.img,
  47.         this.type,
  48.         this.height,
  49.         this.weight,
  50.         this.candy,
  51.         this.candyCount,
  52.         this.egg,
  53.         this.spawnChance,
  54.         this.avgSpawns,
  55.         this.spawnTime,
  56.         this.multipliers,
  57.         this.weaknesses,
  58.         this.nextEvolution});
  59.  
  60.   Pokemon.fromJson(Map<String, dynamic> json) {
  61.     id = json['id'];
  62.     num = json['num'];
  63.     name = json['name'];
  64.     img = json['img'];
  65.     type = json['type'].cast<String>();
  66.     height = json['height'];
  67.     weight = json['weight'];
  68.     candy = json['candy'];
  69.     candyCount = json['candy_count'];
  70.     egg = json['egg'];
  71.     spawnChance = json['spawn_chance'].toString();
  72.     avgSpawns = json['avg_spawns'].toString();
  73.     spawnTime = json['spawn_time'];
  74.     multipliers = json['multipliers']?.cast<double>();
  75.     weaknesses = json['weaknesses'].cast<String>();
  76.     if (json['next_evolution'] != null) {
  77.       nextEvolution = <NextEvolution>[];
  78.       json['next_evolution'].forEach((v) {
  79.         nextEvolution!.add(new NextEvolution.fromJson(v));
  80.       });
  81.     }
  82.   }
  83.  
  84.   Map<String, dynamic> toJson() {
  85.     final Map<String, dynamic> data = new Map<String, dynamic>();
  86.     data['id'] = this.id;
  87.     data['num'] = this.num;
  88.     data['name'] = this.name;
  89.     data['img'] = this.img;
  90.     data['type'] = this.type;
  91.     data['height'] = this.height;
  92.     data['weight'] = this.weight;
  93.     data['candy'] = this.candy;
  94.     data['candy_count'] = this.candyCount;
  95.     data['egg'] = this.egg;
  96.     data['spawn_chance'] = this.spawnChance;
  97.     data['avg_spawns'] = this.avgSpawns;
  98.     data['spawn_time'] = this.spawnTime;
  99.     data['multipliers'] = this.multipliers;
  100.     data['weaknesses'] = this.weaknesses;
  101.     if (this.nextEvolution != null) {
  102.       data['next_evolution'] =
  103.           this.nextEvolution!.map((v) => v.toJson()).toList();
  104.     }
  105.     return data;
  106.   }
  107. }
  108.  
  109. class NextEvolution {
  110.   String? num;
  111.   String? name;
  112.  
  113.   NextEvolution({this.num, this.name});
  114.  
  115.   NextEvolution.fromJson(Map<String, dynamic> json) {
  116.     num = json['num'];
  117.     name = json['name'];
  118.   }
  119.  
  120.   Map<String, dynamic> toJson() {
  121.     final Map<String, dynamic> data = new Map<String, dynamic>();
  122.     data['num'] = this.num;
  123.     data['name'] = this.name;
  124.     return data;
  125.   }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement