Skip to content

Commit 0e476ae

Browse files
committed
BirthdayCalendar logic to filter already added contacts
1 parent 30bc52a commit 0e476ae

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/page/settings_page/settings_screen_manager.dart

+13
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,22 @@ class SettingsScreenManager extends ChangeNotifier {
105105
return;
106106
}
107107

108+
contacts = await _filterAlreadyImportedContacts(contacts);
109+
110+
if (contacts.length == 0) {
111+
_snackbarService.showSnackbarWithMessage(context, noContactsFoundMsg);
112+
return;
113+
}
114+
108115
_handleAddingBirthdaysToContacts(context, contacts);
109116
}
110117

118+
Future<List<Contact>> _filterAlreadyImportedContacts(List<Contact> contacts) async {
119+
List<String> namesOfPeopleWithBirthdays = await _storageService.getAllBirthdays();
120+
List<Contact> filtered = contacts.where((contact) => !namesOfPeopleWithBirthdays.contains(contact.displayName)).toList();
121+
return filtered;
122+
}
123+
111124
void addContactToCalendar(UserBirthday contact) {
112125
_bcContactsService.addContactToCalendar(contact);
113126
}

0 commit comments

Comments
 (0)