The at_contacts_flutter library on the atPlatform
2 min read
Too many atSigns to keep track of? That’s no problem with the at_contacts_flutter package! Simply add the at_contacts_flutter dependency to your project, and you’ll be capable of performing several actions with your atSign contacts.
Be sure to check our pub.dev to see the most up-to-date version at_contacts_flutter!
In order to implement the at_contacts_flutter widget, you must first, of course, create an AtClientService instance and authenticate an atSign. If you look through the example application dedicated to the at_contacts_flutter widget, you will see on load that it asks you to either authenticate an atSign or use one that is already authenticated on your device.
After you have successfully onboarded an atSign, you will be taken to the page where you may choose to show your contacts or show your blocked contacts. On load of this page, the following code will run, creating an AtClientService instance. The contacts service needs to be initialized with the atClient from the AtClientService, current authenticated atSign, and the root domain.
After successfully initializing the contact service, you will now be capable of getting the list of contacts that exist for the authenticated atSign. This is as easy as simply passing the contacts into a variable.
This fetchContacts() function exists in the _contactService file, which can be found within the at_contact’s ‘services’ folder. If you want to do more than just get the list of contacts, you have the capability of adding more contacts to this list, in addition to removing or blocking any. In order to retrieve the list of blocked contacts, it is similar to retrieving the regular list of contacts. The code from the example app demonstrates this well.
To block a contact, it is as easy as calling the blockUnblock method. If a contact is blocked, it will unblock the contact. If the contact is not blocked, it will block it for you.
After you block a contact, you may wish to have that contact removed from the list. All you have to do is simply implement the code below:
Along with the previously stated functionalities, the at_contacts_flutter package also provides the UI so there’s no need to set up a separate page to house these functions!