Compare commits
6 Commits
features/c
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5f75c53866 | |||
| e18863cf1c | |||
| 5bd3b1f18f | |||
| 5b1ffaede8 | |||
| c7be5241a2 | |||
| f11e3f7b63 |
@ -1,32 +1,56 @@
|
||||
PODS:
|
||||
- Flutter (1.0.0)
|
||||
- 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):
|
||||
- sqflite_darwin (0.0.4):
|
||||
- Flutter
|
||||
- FMDB (>= 2.7.5)
|
||||
- FlutterMacOS
|
||||
- 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:
|
||||
- Flutter (from `Flutter`)
|
||||
- sqflite (from `.symlinks/plugins/sqflite/ios`)
|
||||
- sqflite_darwin (from `.symlinks/plugins/sqflite_darwin/darwin`)
|
||||
- sqlite3_flutter_libs (from `.symlinks/plugins/sqlite3_flutter_libs/darwin`)
|
||||
|
||||
SPEC REPOS:
|
||||
trunk:
|
||||
- FMDB
|
||||
- sqlite3
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
Flutter:
|
||||
:path: Flutter
|
||||
sqflite:
|
||||
:path: ".symlinks/plugins/sqflite/ios"
|
||||
sqflite_darwin:
|
||||
:path: ".symlinks/plugins/sqflite_darwin/darwin"
|
||||
sqlite3_flutter_libs:
|
||||
:path: ".symlinks/plugins/sqlite3_flutter_libs/darwin"
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
|
||||
FMDB: 728731dd336af3936ce00f91d9d8495f5718a0e6
|
||||
sqflite: 5b24d06a453c198c13b305ceea4b4286cc07cfe4
|
||||
sqflite_darwin: 20b2a3a3b70e43edae938624ce550a3cbf66a3d0
|
||||
sqlite3: 8d708bc63e9f4ce48f0ad9d6269e478c5ced1d9b
|
||||
sqlite3_flutter_libs: d13b8b3003f18f596e542bcb9482d105577eff41
|
||||
|
||||
PODFILE CHECKSUM: 4305caec6b40dde0ae97be1573c53de1882a07e5
|
||||
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
import '../models/pokemon.dart';
|
||||
import '../utils/pokemon_type.dart';
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
// Classe qui permet de récupérer les données des pokémons depuis l'API
|
||||
// Classe qui permet de récupérer les données des pokémons depuis l'API Tyradex
|
||||
// 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
|
||||
class PokemonApi {
|
||||
static const String baseUrl = 'pokeapi.co';
|
||||
static const String pokemonUrl = 'api/v2/pokemon';
|
||||
static const String baseUrl = 'tyradex.vercel.app';
|
||||
static const String pokemonUrl = 'api/v1/pokemon';
|
||||
|
||||
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 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"));
|
||||
if (response.statusCode != 200) {
|
||||
// Si le code de retour de la requête n'est pas 200, on lève une exception
|
||||
@ -20,15 +20,24 @@ class PokemonApi {
|
||||
}
|
||||
// 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);
|
||||
String name = json['name'];
|
||||
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 du nom en français
|
||||
String name = json['name']['fr'] ?? json['name']['en'] ?? 'unknown';
|
||||
|
||||
// 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
|
||||
return Pokemon(
|
||||
name: name,
|
||||
id: id,
|
||||
type1: PokemonType.values.firstWhere((element) => element.toString() == 'PokemonType.$type1'),
|
||||
type2: type2 != null ? PokemonType.values.firstWhere((element) => element.toString() == 'PokemonType.$type2') : null,
|
||||
type1: type1,
|
||||
type2: type2,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,6 @@ import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'pages/pokemon_list.dart';
|
||||
import 'pages/pokemon_detail.dart';
|
||||
import 'package:sqflite_common/sqflite.dart';
|
||||
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||
|
||||
void main() {
|
||||
|
||||
@ -12,8 +12,8 @@ class Pokemon {
|
||||
PokemonType type1;
|
||||
PokemonType? type2;
|
||||
|
||||
String get imageUrl => 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/$id.png';
|
||||
String get shinyImageUrl => 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/shiny/$id.png';
|
||||
String get imageUrl => 'https://raw.githubusercontent.com/Yarkis01/TyraDex/images/sprites/$id/regular.png';
|
||||
String get shinyImageUrl => 'https://raw.githubusercontent.com/Yarkis01/TyraDex/images/sprites/$id/shiny.png';
|
||||
String get cryUrl => 'https://pokemoncries.com/cries/$id.mp3';
|
||||
|
||||
String get formatedName {
|
||||
|
||||
@ -1,6 +1,31 @@
|
||||
import 'package:flutter/material.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
|
||||
Color typeToColor(PokemonType type) {
|
||||
Map<PokemonType, Color> typeToColor = {
|
||||
|
||||
@ -7,8 +7,7 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:pokedex/main.dart';
|
||||
import 'package:pokeguess/main.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user