Files
GitJournal/lib/core/note_data.dart
Vishesh Handa 20f8d7f7fe NoteEditor: Improve modified check
If the only modification is the addition of a 'modified' tag, then we
shouldn't count it as modified.

I'm not too fond of this logic.
2020-02-09 17:34:12 +01:00

40 lines
1.0 KiB
Dart

import 'dart:collection';
class NoteData {
String body = "";
LinkedHashMap<String, dynamic> props = LinkedHashMap<String, dynamic>();
NoteData([this.body, this.props]) {
body = body ?? "";
// ignore: prefer_collection_literals
props = props ?? LinkedHashMap<String, dynamic>();
}
NoteData.from(NoteData other) {
body = String.fromCharCodes(other.body.codeUnits);
props = LinkedHashMap<String, dynamic>.from(other.props);
}
@override
int get hashCode => body.hashCode ^ props.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is NoteData &&
runtimeType == other.runtimeType &&
body == other.body &&
_equalMaps(props, other.props);
static bool _equalMaps(Map a, Map b) {
if (a.length != b.length) return false;
return a.keys
.every((dynamic key) => b.containsKey(key) && a[key] == b[key]);
}
@override
String toString() {
return 'NoteData{body: $body, props: $props}';
}
}