compareContactListForUpdatedState method
void
compareContactListForUpdatedState()
compares contactList with baseContactList and assigns isBlocking
, isMarkingFav
and isDeleting
for existing atsigns in baseContactList.
Implementation
void compareContactListForUpdatedState() {
for (var c in contactList) {
var index =
baseContactList.indexWhere((e) => e.contact!.atSign == c.atSign);
if (index > -1) {
baseContactList[index] = BaseContact(
c,
isBlocking: baseContactList[index].isBlocking,
isMarkingFav: baseContactList[index].isMarkingFav,
isDeleting: baseContactList[index].isDeleting,
);
} else {
baseContactList.add(
BaseContact(
c,
isBlocking: false,
isMarkingFav: false,
isDeleting: false,
),
);
}
}
// checking to remove deleted atsigns from baseContactList.
var atsignsToRemove = <String>[];
for (var baseContact in baseContactList) {
var index = contactList.indexWhere(
(e) => e.atSign == baseContact.contact!.atSign,
);
if (index == -1) {
atsignsToRemove.add(baseContact.contact!.atSign!);
}
}
for (var e in atsignsToRemove) {
baseContactList.removeWhere((element) => element.contact!.atSign == e);
}
}