contacts_provider 0.1.4 copy "contacts_provider: ^0.1.4" to clipboard
contacts_provider: ^0.1.4 copied to clipboard

Flutter package for observing contact changes, and providing onDelete, onCreate, onUpdate and onChange events.

Under development #

contacts_provider #

add these to android manifest file:

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

Manual initialization #

/main.dart initializing the contacts and asking for permissions.
You can ask for the permissions wherever you like, it is just for the demonstration purposes.

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  // initializing contacts_provider
  final contacts = Contacts();
  await contacts.handlePermissions();
  await contacts.init();

  runApp(const MainApp());
}

Using ContactsBuilder #

/home.dart


class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ContactsBuilder(
      onCreate: (event) {
        // on create behavior goes here

        // you can access the event from here.

        // new contact list after event has happened
        event.contactList;

        // only effected contact list, in case of create
        // it will be the contacts that were created
        event.effectedContacts;
        // event type
        event.event;
      },
      onUpdate: (event) {
        // on update behavior goes here
      },
      onDelete: (event) {
        // on delete behavior goes here
      },
      onChange: () {
        // If you specify this, it will be executed on any changes will happen in contacts;
      },
      builder: (context, allLatestContacts) {
        // receive new list of contacts here.
        return ListView.builder(
          itemCount: allLatestContacts,
          itemBuilder: (BuildContext context, int index) {
            final contact = allLatestContacts[index];
            return ContactListTile(contact: contact);
          },
        );
      },
    );
  }
}

Initializing with ContactsProvider #

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Contacts.handlePermissions();
  runApp(const MainApp());
}


class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return ContactsProvider(
      child: MaterialApp(
        home: Scaffold(
          body: Center(
            child: HomePage(),
          ),
        ),
      ),
    );
  }
}

1
likes
110
pub points
40%
popularity

Publisher

unverified uploader

Flutter package for observing contact changes, and providing onDelete, onCreate, onUpdate and onChange events.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

contacts_service, flutter, listentocontacts, permission_handler, rxdart, shared_preferences

More

Packages that depend on contacts_provider