I want to store a list of Day objects in my sqflite database. The Day class looks like this:
class Day {
String date;
List<DoneTask> doneTasks;
double score = 0;
Day({this.doneTasks, this.date});
}
the DoneTask class:
class DoneTask {
Category category;
double score;
String description;
DoneTask({this.category, this.score, this.description});
}
Category has an attribute id, which is all I want to store from that.
I'm not sure how I can realize that with sqflite.
I was thinking about adding the Attribute String day to the DoneTasks class for loading the DoneTasks in first, and sort them into the Days later. But this does not sound like a good solution for me, has anyone an idea how I could do it in a better way?
I'm very new to using SQL, so id appreciate simple answers/
(this is what I used yet for sqflite: https://flutter.dev/docs/cookbook/persistence/sqlite)
Here is how I would save it :
Dayobject. Inside it you will save only thedateandscoreproperties.The method
Database().insertreturn aFuture<int>which is the id of the newly created row so you can use it to save yourDoneTaskand link them to theDay.List<DoneTask>in another table with a columnid_dayas their identifier.Here is a modelization of what it could look.