Skip to content

Instantly share code, notes, and snippets.

@devxpy
Last active February 7, 2019 06:36
Show Gist options
  • Select an option

  • Save devxpy/652af3315b4438427924ff0c4d418c16 to your computer and use it in GitHub Desktop.

Select an option

Save devxpy/652af3315b4438427924ff0c4d418c16 to your computer and use it in GitHub Desktop.
A demo of how to create a structure of chapter-wise lessons, from a Set of Lesson objects
import 'package:meghshala_app_flutter/core/dynamodb.dart';
import 'package:meghshala_app_flutter/core/lesson_store.dart';
// fetch lessons from database
Set<Lesson> lessons = await DynamoDB.listLessons();
// or, fetch from local storage
Set<Lesson> lessons = await LessonStore.getLessons();
// initialize an empty Map
Map<String, Set<Lesson>> chapterWiseLessons = {};
lessons.forEach((lesson) {
// initialize an empty Set for the lessons of this chapter
if (!chapterWiseLessons.containsKey(lesson.chapterId)) {
chapterWiseLessons[lesson.chapterId] = Set();
}
chapterWiseLessons[lesson.chapterId].add(lesson);
});
print(chapterWiseLessons);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment