Last active
February 7, 2019 06:36
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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