fix(data): race-safe DB open, graceful unknown types, explicit id error + fallback tests
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -32,7 +32,9 @@ class PokemonDto {
|
||||
/// Construit une entité depuis la réponse Tyradex (objet unique ou élément de liste).
|
||||
/// [fallbackId] sert quand le JSON ne contient pas `pokedex_id`.
|
||||
static Pokemon fromTyradexJson(Map<String, dynamic> json, {int? fallbackId}) {
|
||||
final id = (json['pokedex_id'] as int?) ?? fallbackId!;
|
||||
final id = (json['pokedex_id'] as int?) ??
|
||||
fallbackId ??
|
||||
(throw ArgumentError('pokedex_id absent et fallbackId non fourni'));
|
||||
final nameMap = json['name'] as Map<String, dynamic>?;
|
||||
final name = nameMap?['fr'] ?? nameMap?['en'] ?? 'unknown';
|
||||
|
||||
@@ -77,9 +79,15 @@ class PokemonDto {
|
||||
return Pokemon(
|
||||
name: row['name'],
|
||||
id: row['id'],
|
||||
type1: PokemonType.values.firstWhere((e) => e.name == row['type1']),
|
||||
type1: PokemonType.values.firstWhere(
|
||||
(e) => e.name == row['type1'],
|
||||
orElse: () => PokemonType.unknown,
|
||||
),
|
||||
type2: row['type2'] != null
|
||||
? PokemonType.values.firstWhere((e) => e.name == row['type2'])
|
||||
? PokemonType.values.firstWhere(
|
||||
(e) => e.name == row['type2'],
|
||||
orElse: () => PokemonType.unknown,
|
||||
)
|
||||
: null,
|
||||
hp: row['hp'] ?? 0,
|
||||
atk: row['atk'] ?? 0,
|
||||
|
||||
Reference in New Issue
Block a user