listentocontacts 0.0.1+5
listentocontacts: ^0.0.1+5

Flutter Android iOS

Listen to changes to the user's contacts. This uses a ContentObserver on Android and a NotificationCenter observer on iOS.

listentocontacts #

This plugin allows you to listen to changes to the user's contacts.

It uses a ContentObserver in Android and the NotificationCenter observer in iOS.

It does not tell you what contact has been added/edited/deleted. It only tells you that some change has been made to the cotacts.

If you want to know what change has been made, then you will have to query the contacts yourself. You may also need to maintain a copy in a local database to compare to.

Getting Started #

Install the plugin #

In your pubspec.yaml:

dependencies:  
    listentocontacts: ^0.0.1+5

Add the required permissions #

AndroidManifest.xml

<uses-permission android:name="android.permission.READ_CONTACTS" />  
<uses-permission android:name="android.permission.WRITE_CONTACTS" />  

Info.plist

<key>NSContactsUsageDescription</key>  
<string>This app requires contacts access to function properly.</string>  

Ask for permission #

This example uses permission_handler, but you can do this however you want.

Future<PermissionStatus> _getPermission() async {
    final PermissionStatus permission = await Permission.contacts.status;
    if (permission != PermissionStatus.granted &&
        permission != PermissionStatus.denied) {
      final Map<Permission, PermissionStatus> permissionStatus =
      await [Permission.contacts].request();
      return permissionStatus[Permission.contacts] ??
          PermissionStatus.undetermined;
    } else {
      return permission;
    }
  }

final PermissionStatus permissionStatus = await _getPermission();

Initialise the listener #

Listentocontacts().onContactsChanged.listen((_) {
      // do what you want to do here when your contacts have changed
    });

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

2
likes
100
pub points
60%
popularity

Listen to changes to the user's contacts. This uses a ContentObserver on Android and a NotificationCenter observer on iOS.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

benbaert246@gmail.com

License

BSD (LICENSE)

Dependencies

flutter

More

Packages that depend on listentocontacts