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.getKuralsByEnglishChapterName,
    );

    debugPrint(response.toJson().toString());

    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) {
    debugPrint('Error while fetching english chapter kurals: $e, $stackTrace');
    englishChapterNameKuralsErrorMessage = 'Error while fetching kurals: $e';
  }
  notifyListeners();
}