I have an app in Flutter where users can add some book chapters to their profile and read it.
Now I want to create a training system when the user has read a chapter, the app marks it as read.
I’m using Firebase Firestore like this
I was thinking to add a "read" field in the chapter document but it will result in every user will have the mark "read" in the app.
So, how to create a tracking system that allows marking read chapters just for the current user?
2
Answers
You need to create such field for users collection. For example, creating "read chapters" named field (readed is not grammatically correct) which is an array, accepting String. If a user read, then you add this chapter’s name to this user’s doc(to "read chapters" field I mean). So you can check like that,
array.contains("chapter_name")
and mark the chapter as read or unread. That is all.The best option that you have is to store all those chapters in an array in the user object:
Or in a Map:
If you’re afraid about the 1 MiB maximum limitation of a document, then I recommend you create a document for the starting letter of a chapter:
In this way, you’ll be able to store 26 MiB of data, which is pretty much.