getTopicsForBook method

Future<List<TopicModel>> getTopicsForBook(
  1. String bookId
)

Fetch all topics belonging to a specific book.

Implementation

Future<List<TopicModel>> getTopicsForBook(String bookId) async {
  final response = await _client
      .from('topics')
      .select()
      .eq('book_id', bookId)
      .order('sort_order', ascending: true);
  final flat = (response as List<dynamic>)
      .map((row) => TopicModel.fromJson(row as Map<String, dynamic>))
      .toList();
  return TopicModel.buildTree(flat);
}