getHadiths method

Future<List<Hadith>> getHadiths(
  1. Collection collection,
  2. int bookNumber
)

Fetches all hadiths for a specific book in a collection.

Implementation

Future<List<Hadith>> getHadiths(
  Collection collection,
  int bookNumber,
) async {
  Map<String, dynamic> hadithsData = await _loadHadiths(collection);
  String bookKey = bookNumber.toString();

  if (!hadithsData.containsKey(bookKey)) {
    throw Exception(
      'Hadiths not found for book number $bookNumber in $collection.',
    );
  }

  List<dynamic> hadithList = hadithsData[bookKey];
  return hadithList.map((json) => Hadith.fromJson(json)).toList();
}