loadDiseases method
- AppLocalizations localizations
Loads all diseases 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> loadDiseases(AppLocalizations localizations) async {
try {
_state = DiseaseInfoState.loading;
_errorMessage = null; // Clear previous errors
notifyListeners();
final diseasesList = await _repository.getAllDiseases(
localizations.localeName,
);
_diseases = diseasesList;
_state = DiseaseInfoState.loaded;
notifyListeners();
} catch (e) {
_state = DiseaseInfoState.error;
_errorMessage = localizations.viewModelErrorFailedToLoadDiseases(
e.toString(),
);
notifyListeners();
}
}