getKuralsByEnglishChapterNames method

Future getKuralsByEnglishChapterNames({
  1. required String chapterName,
})

Implementation

Future getKuralsByEnglishChapterNames({required String chapterName}) async {
  isAllEnglishChaptersKuralsLoaded = false;
  englishChapterNameKuralsList.clear();
  englishChapterNameKuralsErrorMessage = '';

  try {
    ApiResponse response = await ApiServices.get(
      requestHeaders: {},
      requestParams: {'englishChapterName': chapterName},
      endpoint: UrlServices.GET_ALL_KURALS_BY_ENGLISH_CHAPTER_NAMES,
    );

    logger.w(response.toJson());

    if (response.status != null && response.status!) {
      List<dynamic> responseList = response.response ?? [];
      englishChapterNameKuralsList = responseList.map((e) => Kural.fromJson(e)).toList();
      isAllEnglishChaptersKuralsLoaded = true;
    } else {
      englishChapterNameKuralsErrorMessage =
          response.message ?? 'Server error, failed to load kurals.';
    }
  } catch (e, stackTrace) {
    logger.e('Error while fetching english chapter kurals: $e, $stackTrace');
    englishChapterNameKuralsErrorMessage = 'Error while fetching kurals: $e';
  }

  state = state.copyWithEnglishChapterNameKurals(
    englishChapterNameKuralsList: englishChapterNameKuralsList,
    isAllEnglishChaptersKuralsLoaded: isAllEnglishChaptersKuralsLoaded,
    englishChapterNameKuralsErrorMessage: englishChapterNameKuralsErrorMessage,
  );
}