relatica/lib/models/entry_tree_item.dart
2022-11-18 16:50:15 -05:00

44 lines
976 B
Dart

import 'timeline_entry.dart';
class EntryTreeItem {
final TimelineEntry entry;
final bool isMine;
bool isOrphaned;
final _children = <String, EntryTreeItem>{};
EntryTreeItem(this.entry, {this.isMine = true, this.isOrphaned = false});
EntryTreeItem copy({required TimelineEntry entry}) => EntryTreeItem(
entry,
isMine: isMine,
isOrphaned: isOrphaned,
);
String get id => entry.id;
void addChild(EntryTreeItem child) {
_children[child.id] = child;
}
int get totalChildren {
int t = _children.length;
for (final c in _children.values) {
t += c.totalChildren;
}
return t;
}
List<EntryTreeItem> get children => List.unmodifiable(_children.values);
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is EntryTreeItem &&
runtimeType == other.runtimeType &&
entry == other.entry;
@override
int get hashCode => entry.hashCode;
}