getChapterFilenames method Null safety

List<String> getChapterFilenames(
  1. String chapterID,
  2. ChapterData chapters,
  3. bool isDataSaverMode
)

Implementation

List<String> getChapterFilenames(
    String chapterID, ChapterData chapters, bool isDataSaverMode) {
  for (var i = 0; i < chapters.result.length; i++) {
    if (chapters.result[i].data.id == chapterID) {
      if (isDataSaverMode == false) {
        return chapters.result[i].data.attributes.chapterData;
      } else if (isDataSaverMode == true) {
        return chapters.result[i].data.attributes.chapterDataSaver;
      }
    } else {
      print('Chapter by ID $chapterID not found');
    }
  }
  return <String>[];
}