Created
August 4, 2019 18:36
-
-
Save felangel/22257ec4c8c0fbfabcb9bacb78248a0b to your computer and use it in GitHub Desktop.
[flutter_firestore_todos] todo model
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:meta/meta.dart'; | |
import '../entities/entities.dart'; | |
@immutable | |
class Todo { | |
final bool complete; | |
final String id; | |
final String note; | |
final String task; | |
Todo(this.task, {this.complete = false, String note = '', String id}) | |
: this.note = note ?? '', | |
this.id = id; | |
Todo copyWith({bool complete, String id, String note, String task}) { | |
return Todo( | |
task ?? this.task, | |
complete: complete ?? this.complete, | |
id: id ?? this.id, | |
note: note ?? this.note, | |
); | |
} | |
@override | |
int get hashCode => | |
complete.hashCode ^ task.hashCode ^ note.hashCode ^ id.hashCode; | |
@override | |
bool operator ==(Object other) => | |
identical(this, other) || | |
other is Todo && | |
runtimeType == other.runtimeType && | |
complete == other.complete && | |
task == other.task && | |
note == other.note && | |
id == other.id; | |
@override | |
String toString() { | |
return 'Todo { complete: $complete, task: $task, note: $note, id: $id }'; | |
} | |
TodoEntity toEntity() { | |
return TodoEntity(task, id, note, complete); | |
} | |
static Todo fromEntity(TodoEntity entity) { | |
return Todo( | |
entity.task, | |
complete: entity.complete ?? false, | |
note: entity.note, | |
id: entity.id, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment