getBook method

Future<Book> getBook(
  1. Collection collection,
  2. int bookNumber
)

Fetches a specific book by its number from a collection.

Implementation

Future<Book> getBook(Collection collection, int bookNumber) async {
  List<Book> books = await getBooks(collection);
  return books.firstWhere(
    (book) => book.bookNumber == bookNumber.toString(),
    orElse: () => throw Exception(
      'Book number $bookNumber not found in $collection.',
    ),
  );
}