Created
August 4, 2019 18:34
-
-
Save felangel/a3c4670385dea80afa2e49856c3eefb9 to your computer and use it in GitHub Desktop.
[flutter_firestore_todos] todo entity
This file contains 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:cloud_firestore/cloud_firestore.dart'; | |
import 'package:equatable/equatable.dart'; | |
class TodoEntity extends Equatable { | |
final bool complete; | |
final String id; | |
final String note; | |
final String task; | |
TodoEntity(this.task, this.id, this.note, this.complete); | |
Map<String, Object> toJson() { | |
return { | |
'complete': complete, | |
'task': task, | |
'note': note, | |
'id': id, | |
}; | |
} | |
@override | |
String toString() { | |
return 'TodoEntity { complete: $complete, task: $task, note: $note, id: $id }'; | |
} | |
static TodoEntity fromJson(Map<String, Object> json) { | |
return TodoEntity( | |
json['task'] as String, | |
json['id'] as String, | |
json['note'] as String, | |
json['complete'] as bool, | |
); | |
} | |
static TodoEntity fromSnapshot(DocumentSnapshot snap) { | |
return TodoEntity( | |
snap.data['task'], | |
snap.documentID, | |
snap.data['note'], | |
snap.data['complete'], | |
); | |
} | |
Map<String, Object> toDocument() { | |
return { | |
'complete': complete, | |
'task': task, | |
'note': note, | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment