patch guess langue issue
This commit is contained in:
@@ -7,6 +7,7 @@ import '../../domain/game/game_engine.dart';
|
||||
import '../../domain/game/game_state.dart';
|
||||
import '../../core/logger.dart';
|
||||
import 'gen_filter_provider.dart';
|
||||
import 'locale_provider.dart';
|
||||
import 'pokedex_provider.dart';
|
||||
import 'repository_provider.dart';
|
||||
|
||||
@@ -17,7 +18,28 @@ class GameNotifier extends Notifier<GameState> {
|
||||
final _random = Random();
|
||||
|
||||
@override
|
||||
GameState build() => const GameState();
|
||||
GameState build() {
|
||||
// Re-fetch the current Pokémon whenever the locale changes so the name
|
||||
// (used for hints and the guess comparison) switches language instantly.
|
||||
ref.listen(localeProvider, (_, __) => _reloadCurrentPokemon());
|
||||
return const GameState();
|
||||
}
|
||||
|
||||
Future<void> _reloadCurrentPokemon() async {
|
||||
final current = state.currentPokemon;
|
||||
if (current == null || state.status == GameStatus.loading) return;
|
||||
try {
|
||||
final updated = await ref.read(pokemonRepositoryProvider).getById(current.id);
|
||||
if (updated != null) {
|
||||
state = state.copyWith(
|
||||
currentPokemon: updated.copyWith(
|
||||
isCaught: current.isCaught,
|
||||
isSeen: current.isSeen,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> startNewGame() async {
|
||||
state = _engine.newGame(state);
|
||||
|
||||
Reference in New Issue
Block a user