mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-15 07:56:11 +08:00
70 lines
1.4 KiB
Dart
70 lines
1.4 KiB
Dart
typedef NoteAdder(Note note);
|
|
typedef NoteRemover(Note note);
|
|
typedef NoteUpdator(Note note);
|
|
|
|
class Note implements Comparable {
|
|
String id;
|
|
DateTime createdAt;
|
|
String body;
|
|
|
|
Note({this.createdAt, this.body, this.id});
|
|
|
|
factory Note.fromJson(Map<String, dynamic> json) {
|
|
String id;
|
|
if (json.containsKey("id")) {
|
|
var val = json["id"];
|
|
if (val.runtimeType == String) {
|
|
id = val;
|
|
} else {
|
|
id = val.toString();
|
|
}
|
|
}
|
|
|
|
return new Note(
|
|
id: id,
|
|
createdAt: DateTime.parse(json['createdAt']),
|
|
body: json['body'],
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
"createdAt": createdAt.toIso8601String(),
|
|
"body": body,
|
|
"id": id,
|
|
};
|
|
}
|
|
|
|
@override
|
|
int get hashCode => id.hashCode ^ createdAt.hashCode ^ body.hashCode;
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
identical(this, other) ||
|
|
other is Note &&
|
|
runtimeType == other.runtimeType &&
|
|
id == other.id &&
|
|
body == other.body &&
|
|
createdAt == other.createdAt;
|
|
|
|
@override
|
|
String toString() {
|
|
return 'Note{id: $id, body: $body, createdAt: $createdAt}';
|
|
}
|
|
|
|
@override
|
|
int compareTo(other) => createdAt.compareTo(other.createdAt);
|
|
}
|
|
|
|
class AppState {
|
|
bool isLoading;
|
|
List<Note> notes;
|
|
|
|
AppState({
|
|
this.isLoading = false,
|
|
this.notes = const [],
|
|
});
|
|
|
|
factory AppState.loading() => AppState(isLoading: true);
|
|
}
|