loadMosquitoSpecies method
- AppLocalizations localizations
Loads all mosquito species from the repository
Updates the state to loading while fetching and notifies listeners when complete. Handles any errors that occur during loading.
localizations: Localization instance for error messages
Implementation
Future<void> loadMosquitoSpecies(AppLocalizations localizations) async {
try {
_state = GalleryState.loading;
_errorMessage = null; // Clear previous errors
notifyListeners();
final speciesList = await _repository.getAllMosquitoSpecies(
localizations.localeName,
);
_mosquitoSpecies = speciesList;
_state = GalleryState.loaded;
notifyListeners();
} catch (e) {
_state = GalleryState.error;
_errorMessage = localizations.viewModelErrorFailedToLoadMosquitoSpecies(
e.toString(),
);
notifyListeners();
}
}