Compare commits
No commits in common. "e18863cf1c59887dc474654db395e1dd30e6c1e8" and "652eb9072f83e11421cb1288e75e9b267995a0c3" have entirely different histories.
e18863cf1c
...
652eb9072f
@ -1,56 +1,32 @@
|
|||||||
PODS:
|
PODS:
|
||||||
- Flutter (1.0.0)
|
- Flutter (1.0.0)
|
||||||
- sqflite_darwin (0.0.4):
|
- FMDB (2.7.12):
|
||||||
|
- FMDB/standard (= 2.7.12)
|
||||||
|
- FMDB/Core (2.7.12)
|
||||||
|
- FMDB/standard (2.7.12):
|
||||||
|
- FMDB/Core
|
||||||
|
- sqflite (0.0.3):
|
||||||
- Flutter
|
- Flutter
|
||||||
- FlutterMacOS
|
- FMDB (>= 2.7.5)
|
||||||
- sqlite3 (3.51.1):
|
|
||||||
- sqlite3/common (= 3.51.1)
|
|
||||||
- sqlite3/common (3.51.1)
|
|
||||||
- sqlite3/dbstatvtab (3.51.1):
|
|
||||||
- sqlite3/common
|
|
||||||
- sqlite3/fts5 (3.51.1):
|
|
||||||
- sqlite3/common
|
|
||||||
- sqlite3/math (3.51.1):
|
|
||||||
- sqlite3/common
|
|
||||||
- sqlite3/perf-threadsafe (3.51.1):
|
|
||||||
- sqlite3/common
|
|
||||||
- sqlite3/rtree (3.51.1):
|
|
||||||
- sqlite3/common
|
|
||||||
- sqlite3/session (3.51.1):
|
|
||||||
- sqlite3/common
|
|
||||||
- sqlite3_flutter_libs (0.0.1):
|
|
||||||
- Flutter
|
|
||||||
- FlutterMacOS
|
|
||||||
- sqlite3 (~> 3.51.1)
|
|
||||||
- sqlite3/dbstatvtab
|
|
||||||
- sqlite3/fts5
|
|
||||||
- sqlite3/math
|
|
||||||
- sqlite3/perf-threadsafe
|
|
||||||
- sqlite3/rtree
|
|
||||||
- sqlite3/session
|
|
||||||
|
|
||||||
DEPENDENCIES:
|
DEPENDENCIES:
|
||||||
- Flutter (from `Flutter`)
|
- Flutter (from `Flutter`)
|
||||||
- sqflite_darwin (from `.symlinks/plugins/sqflite_darwin/darwin`)
|
- sqflite (from `.symlinks/plugins/sqflite/ios`)
|
||||||
- sqlite3_flutter_libs (from `.symlinks/plugins/sqlite3_flutter_libs/darwin`)
|
|
||||||
|
|
||||||
SPEC REPOS:
|
SPEC REPOS:
|
||||||
trunk:
|
trunk:
|
||||||
- sqlite3
|
- FMDB
|
||||||
|
|
||||||
EXTERNAL SOURCES:
|
EXTERNAL SOURCES:
|
||||||
Flutter:
|
Flutter:
|
||||||
:path: Flutter
|
:path: Flutter
|
||||||
sqflite_darwin:
|
sqflite:
|
||||||
:path: ".symlinks/plugins/sqflite_darwin/darwin"
|
:path: ".symlinks/plugins/sqflite/ios"
|
||||||
sqlite3_flutter_libs:
|
|
||||||
:path: ".symlinks/plugins/sqlite3_flutter_libs/darwin"
|
|
||||||
|
|
||||||
SPEC CHECKSUMS:
|
SPEC CHECKSUMS:
|
||||||
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
|
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
|
||||||
sqflite_darwin: 20b2a3a3b70e43edae938624ce550a3cbf66a3d0
|
FMDB: 728731dd336af3936ce00f91d9d8495f5718a0e6
|
||||||
sqlite3: 8d708bc63e9f4ce48f0ad9d6269e478c5ced1d9b
|
sqflite: 5b24d06a453c198c13b305ceea4b4286cc07cfe4
|
||||||
sqlite3_flutter_libs: d13b8b3003f18f596e542bcb9482d105577eff41
|
|
||||||
|
|
||||||
PODFILE CHECKSUM: 4305caec6b40dde0ae97be1573c53de1882a07e5
|
PODFILE CHECKSUM: 4305caec6b40dde0ae97be1573c53de1882a07e5
|
||||||
|
|
||||||
|
|||||||
@ -1,18 +1,18 @@
|
|||||||
import '../models/pokemon.dart';
|
import '../models/pokemon.dart';
|
||||||
import '../utils/pokemon_type.dart';
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
// Classe qui permet de récupérer les données des pokémons depuis l'API Tyradex
|
// Classe qui permet de récupérer les données des pokémons depuis l'API
|
||||||
// On utilise la librairie http pour effectuer les requêtes
|
// On utilise la librairie http pour effectuer les requêtes
|
||||||
// On utilise la librairie dart:convert pour convertir les données JSON en objet Dart
|
// On utilise la librairie dart:convert pour convertir les données JSON en objet Dart
|
||||||
class PokemonApi {
|
class PokemonApi {
|
||||||
static const String baseUrl = 'tyradex.vercel.app';
|
static const String baseUrl = 'pokeapi.co';
|
||||||
static const String pokemonUrl = 'api/v1/pokemon';
|
static const String pokemonUrl = 'api/v2/pokemon';
|
||||||
|
|
||||||
static Future<Pokemon> getPokemon(int id) async {
|
static Future<Pokemon> getPokemon(int id) async {
|
||||||
// On utilise la méthode get de la classe http pour effectuer une requête GET
|
// On utilise la méthode get de la classe http pour effectuer une requête GET
|
||||||
// On utilise Uri.https pour construire l'URL de la requête
|
// On utilise Uri.https pour construire l'URL de la requête
|
||||||
|
// URI.https prends en paramètre le nom de domaine et le chemin de la requête
|
||||||
var response = await http.get(Uri.https(baseUrl, "$pokemonUrl/$id"));
|
var response = await http.get(Uri.https(baseUrl, "$pokemonUrl/$id"));
|
||||||
if (response.statusCode != 200) {
|
if (response.statusCode != 200) {
|
||||||
// Si le code de retour de la requête n'est pas 200, on lève une exception
|
// Si le code de retour de la requête n'est pas 200, on lève une exception
|
||||||
@ -20,24 +20,15 @@ class PokemonApi {
|
|||||||
}
|
}
|
||||||
// On utilise la méthode jsonDecode de la librairie dart:convert pour convertir le corps de la réponse en fichier JSON
|
// On utilise la méthode jsonDecode de la librairie dart:convert pour convertir le corps de la réponse en fichier JSON
|
||||||
var json = jsonDecode(response.body);
|
var json = jsonDecode(response.body);
|
||||||
// Récupération du nom en français
|
String name = json['name'];
|
||||||
String name = json['name']['fr'] ?? json['name']['en'] ?? 'unknown';
|
String type1 = (json['types'].length > 0 && json['types'][0]['type'] != null && json['types'][0]['type']['name'] != null) ? json['types'][0]['type']['name'] : "unknown";
|
||||||
|
String? type2 = (json['types'].length > 1 && json['types'][1]['type'] != null && json['types'][1]['type']['name'] != null) ? json['types'][1]['type']['name'] : null;
|
||||||
// Récupération des types (en français dans l'API Tyradex)
|
|
||||||
List types = json['types'] ?? [];
|
|
||||||
PokemonType type1 = types.isNotEmpty
|
|
||||||
? frenchTypeToEnum(types[0]['name'])
|
|
||||||
: PokemonType.unknown;
|
|
||||||
PokemonType? type2 = types.length > 1
|
|
||||||
? frenchTypeToEnum(types[1]['name'])
|
|
||||||
: null;
|
|
||||||
|
|
||||||
// On crée un objet Pokemon à partir du fichier JSON
|
// On crée un objet Pokemon à partir du fichier JSON
|
||||||
return Pokemon(
|
return Pokemon(
|
||||||
name: name,
|
name: name,
|
||||||
id: id,
|
id: id,
|
||||||
type1: type1,
|
type1: PokemonType.values.firstWhere((element) => element.toString() == 'PokemonType.$type1'),
|
||||||
type2: type2,
|
type2: type2 != null ? PokemonType.values.firstWhere((element) => element.toString() == 'PokemonType.$type2') : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,6 +2,7 @@ import 'dart:io';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'pages/pokemon_list.dart';
|
import 'pages/pokemon_list.dart';
|
||||||
import 'pages/pokemon_detail.dart';
|
import 'pages/pokemon_detail.dart';
|
||||||
|
import 'package:sqflite_common/sqflite.dart';
|
||||||
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|||||||
@ -12,8 +12,8 @@ class Pokemon {
|
|||||||
PokemonType type1;
|
PokemonType type1;
|
||||||
PokemonType? type2;
|
PokemonType? type2;
|
||||||
|
|
||||||
String get imageUrl => 'https://raw.githubusercontent.com/Yarkis01/TyraDex/images/sprites/$id/regular.png';
|
String get imageUrl => 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/$id.png';
|
||||||
String get shinyImageUrl => 'https://raw.githubusercontent.com/Yarkis01/TyraDex/images/sprites/$id/shiny.png';
|
String get shinyImageUrl => 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/shiny/$id.png';
|
||||||
String get cryUrl => 'https://pokemoncries.com/cries/$id.mp3';
|
String get cryUrl => 'https://pokemoncries.com/cries/$id.mp3';
|
||||||
|
|
||||||
String get formatedName {
|
String get formatedName {
|
||||||
|
|||||||
@ -1,31 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../models/pokemon.dart';
|
import '../models/pokemon.dart';
|
||||||
|
|
||||||
// Convertit un nom de type français (de l'API Tyradex) en PokemonType
|
|
||||||
PokemonType frenchTypeToEnum(String frenchType) {
|
|
||||||
const Map<String, PokemonType> frenchToEnglish = {
|
|
||||||
'Normal': PokemonType.normal,
|
|
||||||
'Combat': PokemonType.fighting,
|
|
||||||
'Vol': PokemonType.flying,
|
|
||||||
'Poison': PokemonType.poison,
|
|
||||||
'Sol': PokemonType.ground,
|
|
||||||
'Roche': PokemonType.rock,
|
|
||||||
'Insecte': PokemonType.bug,
|
|
||||||
'Spectre': PokemonType.ghost,
|
|
||||||
'Acier': PokemonType.steel,
|
|
||||||
'Feu': PokemonType.fire,
|
|
||||||
'Eau': PokemonType.water,
|
|
||||||
'Plante': PokemonType.grass,
|
|
||||||
'Électrik': PokemonType.electric,
|
|
||||||
'Psy': PokemonType.psychic,
|
|
||||||
'Glace': PokemonType.ice,
|
|
||||||
'Dragon': PokemonType.dragon,
|
|
||||||
'Ténèbres': PokemonType.dark,
|
|
||||||
'Fée': PokemonType.fairy,
|
|
||||||
};
|
|
||||||
return frenchToEnglish[frenchType] ?? PokemonType.unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Permet de mapper un type de Pokémon avec une couleur
|
// Permet de mapper un type de Pokémon avec une couleur
|
||||||
Color typeToColor(PokemonType type) {
|
Color typeToColor(PokemonType type) {
|
||||||
Map<PokemonType, Color> typeToColor = {
|
Map<PokemonType, Color> typeToColor = {
|
||||||
@ -57,4 +32,4 @@ Color typeToColor(PokemonType type) {
|
|||||||
String formatedTypeName(PokemonType type) {
|
String formatedTypeName(PokemonType type) {
|
||||||
String typeName = type.toString().split('.').last.replaceAll('PokemonType.', '');
|
String typeName = type.toString().split('.').last.replaceAll('PokemonType.', '');
|
||||||
return typeName[0].toUpperCase() + typeName.substring(1);
|
return typeName[0].toUpperCase() + typeName.substring(1);
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user