unifiedpush 6.0.0-rc3 copy "unifiedpush: ^6.0.0-rc3" to clipboard
unifiedpush: ^6.0.0-rc3 copied to clipboard

Push notifications with the provider chosen by the user.

UnifiedPush library #

Library to subscribe and receive push notifications with UnifiedPush.

To receive notifications with UnifiedPush, users must have a dedicated application, a distributor, installed on their system.

Initialize the receiver #

When you initialize your application, register the different functions that will handle the incoming events with [UnifiedPush.initialize]:

UnifiedPush.initialize(
  onNewEndpoint: onNewEndpoint,
  onRegistrationFailed: onRegistrationFailed,
  onUnregistered: onUnregistered,
  onMessage: onMessage,
).then((registered) => { if (registered) UnifiedPush.register(instance) });

void onNewEndpoint(PushEndpoint endpoint, String instance) {
  // You should send the endpoint to your application server
  // and sync for missing notifications.
}

void onRegistrationFailed(FailedReason reason, String instance) {}

void onUnregistered(String instance) {}

void onMessage(PushMessage message, String instance) {}
copied to clipboard

Register for push messages #

When you try to register for the first time, you will probably want to use the user default distributor:

UnifiedPush.tryUseCurrentOrDefaultDistributor().then((success) {
  debugPrint("Current or Default found=$success");
  if (success) {
    UnifiedPush.registerApp(
        instance,                        // Optionnal String, to get multiple endpoints (one per instance)
        features = []                    // Optionnal String Array with required features, if a platform needs it
        vapid = vapid                    // Optionnal String with the server public VAPID key
    );
  } else {
    getUserChoice();                     // You UI function to has the distributor to use
  }
});
copied to clipboard

If using the current distrbutor doesn't succeed, or when you want to let the user chose a non-default distrbutor, you can implement your own logic:

void getUserChoice() {
  // Get a list of distributors that are available
  final distributors = await UnifiedPush.getDistributors(
      []                               // Optionnal String Array with required features
  );
  // select one or show a dialog or whatever
  final distributor = myPickerFunc(distributors);
  // save the distributor
  UnifiedPush.saveDistributor(distributor);
  // register your app to the distributor
  UnifiedPush.registerApp(
      instance,                        // Optionnal String, to get multiple endpoints (one per instance)
      features = []                    // Optionnal String Array with required features, if a platform needs it
      vapid = vapid                    // Optionnal String with the server public VAPID key
  );
}
copied to clipboard

If you want, unifiedpush_ui provides a dialog to pick the user choice.

Unregister #

A registration can be canceled with UnifiedPush.unregister.

Embed a distributor #

On Android, this is possible to embed a distributor that will register to the Google play services directly. For more information refer to https://unifiedpush.org/kdoc/embedded_fcm_distributor/.

Send push messages #

You can then send web push messages to your applications. The messages need to be encrypted. The required information them are retrieved onNewEndpoint: [PushEndpoint.pubKeySet]

Example #

An example app can be found on the repository.

15
likes
150
points
4.74k
downloads

Publisher

verified publisherunifiedpush.org

Weekly Downloads

2024.09.21 - 2025.04.05

Push notifications with the provider chosen by the user.

Homepage
Repository
View/report issues

Documentation

Documentation
API reference

License

Apache-2.0 (license)

Dependencies

flutter, unifiedpush_android, unifiedpush_platform_interface

More

Packages that depend on unifiedpush