forked from brianegan/flutter_architecture_samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.dart
61 lines (50 loc) · 1.55 KB
/
models.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2018 The Flutter Architecture Sample Authors. All rights reserved.
// Use of this source code is governed by the MIT license that can be found
// in the LICENSE file.
import 'package:todos_app_core/todos_app_core.dart';
import 'package:todos_repository_core/todos_repository_core.dart';
enum AppTab { todos, stats }
enum ExtraAction { toggleAllComplete, clearCompleted }
class Todo {
final bool complete;
final String id;
final String note;
final String task;
Todo(this.task, {this.complete = false, this.note = '', String id})
: this.id = id ?? Uuid().generateV4();
@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,
);
}
Todo copy({String task, bool complete, String note, String id}) {
return Todo(
task ?? this.task,
complete: complete ?? this.complete,
note: note ?? this.note,
id: id ?? this.id,
);
}
}