getTamilChapterNames method

Future getTamilChapterNames()

Implementation

Future getTamilChapterNames() async{
  isAllTamilChaptersLoaded = false;
  tamilChapterNamesList.clear();
  tamilChapterNamesErrorMessage = '';

  try {
    ApiResponse response = await ApiServices.get(
        requestHeaders: {},
        requestParams: {},
        endpoint: UrlServices.GET_ALL_TAMIL_CHAPTERS_NAMES
    );

    logger.w(response.toJson());

    if (response.status != null && response.status!) {
      List<dynamic> responseList = response.response ?? [];
      if(responseList.isNotEmpty) {
        for(var tamilChapterName in responseList){
          tamilChapterNamesList.add(tamilChapterName);
          isAllTamilChaptersLoaded = true;
        }
      } else{
        tamilChapterNamesErrorMessage = response.message ?? 'No response from server.';
      }
    } else {
      tamilChapterNamesErrorMessage = response.message ??
          'Server error, failed to load tamil chapter names, please try again later.';
    }
  } catch (e, stackTrace) {
    logger.e('Error while fetching all kurals: $e, $stackTrace');
    tamilChapterNamesErrorMessage = 'Error while fetching all tamil chapter names: $e';
  }

  state = state.copyWithTamilChapterNames(
      isAllTamilChaptersLoaded: isAllTamilChaptersLoaded,
      tamilChapterNamesList: tamilChapterNamesList,
      tamilChapterNamesErrorMessage: tamilChapterNamesErrorMessage
  );
}