Skip to content

Instantly share code, notes, and snippets.

@jayjonas1996
Last active May 3, 2019 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayjonas1996/7538cacbb4d6762cca2475ab9b81f041 to your computer and use it in GitHub Desktop.
Save jayjonas1996/7538cacbb4d6762cca2475ab9b81f041 to your computer and use it in GitHub Desktop.
Note class
class Note {
int id;
String title;
String content;
DateTime date_created;
DateTime date_last_edited;
Color note_color;
int is_archived = 0;
Note(this.id, this.title, this.content, this.date_created, this.date_last_edited,this.note_color);
Map<String, dynamic> toMap(bool forUpdate) {
var data = {
// 'id': id, since id is auto incremented in the database we don't need to send it to the insert query.
'title': utf8.encode(title),
'content': utf8.encode( content ),
'date_created': epochFromDate( date_created ),
'date_last_edited': epochFromDate( date_last_edited ),
'note_color': note_color.value,
'is_archived': is_archived // for later use for integrating archiving
};
if(forUpdate){ data["id"] = this.id; }
return data;
}
// Converting the date time object into int representing seconds passed after midnight 1st Jan, 1970 UTC
int epochFromDate(DateTime dt) { return dt.millisecondsSinceEpoch ~/ 1000; }
void archiveThisNote(){ is_archived = 1; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment