Skip to content

Instantly share code, notes, and snippets.

@felangel
Created August 4, 2019 18: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 felangel/a3c4670385dea80afa2e49856c3eefb9 to your computer and use it in GitHub Desktop.
Save felangel/a3c4670385dea80afa2e49856c3eefb9 to your computer and use it in GitHub Desktop.
[flutter_firestore_todos] todo entity
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