Methods
Basic Usage
import 'package:cleverpush_flutter/cleverpush_flutter.dart';
// init with autoRegister:false to manually subscribe later
await CleverPush.shared.init("INSERT_CLEVERPUSH_CHANNEL_ID_HERE", false);
// init with autoRegister:true to automatic subscribe
await CleverPush.shared.init("INSERT_CLEVERPUSH_CHANNEL_ID_HERE", true);
// subscribe
CleverPush.shared.subscribe();
// unsubscribe
CleverPush.shared.unsubscribe();
// Get the subscription success callback with subscriptionId
CleverPush.shared.setSubscribedHandler((subscriptionId) {
print("Subscribed: ${subscriptionId}");
});
// Get the subscription status by execute the following code
CleverPush.shared.isSubscribed().then((status) {
console.log(status);
});
Show/Hide Foreground Notifications
CleverPush.shared.setShowNotificationsInForeground(false);
Topics
// get all the subscription topics
var subscriptionTopics = await CleverPush.shared.getSubscriptionTopics();
// set multiple subscription topics
List<String> topics = ['ID_1', 'ID_2'];
CleverPush.shared.setSubscriptionTopics(topics);
// let the user choose his topics
CleverPush.shared.showTopicsDialog();
// get all the available topics
var availableTopics = await CleverPush.shared.getAvailableTopics();
Here is how the topics dialog looks like:
Tags
// get all the subscription tags
var subscriptionTags = await CleverPush.shared.getSubscriptionTags();
// add or remove tags by their ID
CleverPush.shared.addSubscriptionTag('TAG_ID');
CleverPush.shared.removeSubscriptionTag('TAG_ID');
// get all the available tags
var availableTags = await CleverPush.shared.getAvailableTags();
Attributes
// get all the subscription attributes
var subscriptionAttributes = await CleverPush.shared.getSubscriptionAttributes();
// set attribute values by their ID
CleverPush.shared.setSubscriptionAttribute('ATTRIBUTE_ID', 'ATTRIBUTE_VALUE');
var attributeValue = await CleverPush.shared.getSubscriptionAttribute('ATTRIBUTE_ID');
// get all the available attributes
var availableAttributes = await CleverPush.shared.getAvailableAttributes();
Notifications
// Get the notification callback once you recieve the notification
CleverPush.shared.setNotificationReceivedHandler((CPNotificationReceivedResult result) {
print("Notification received: \n${result.notification.jsonRepresentation()}");
});
// Get the notification callback once you open the notification
CleverPush.shared.setNotificationOpenedHandler((CPNotificationOpenedResult result) {
print("Notification opened: \n${result.notification.jsonRepresentation()}");
});
// Get all the recieved notification
var notifications = await CleverPush.shared.getNotifications();
// get remote notification and local notification based on the boolean argument.
// - if you pass boolean argument YES you will get the list of remote notification else you will get the locally stored notification.
bool combineWithApi = true;
var remoteNotifications = await CleverPush.shared.getNotificationsWithApi(combineWithApi);
Tracking Consent
You can optionally require a tracking consent from the user (e.g. you get this consent from a CMP). If you tell our SDK to wait for the tracking consent, it will not call any tracking-related features until the consent is available. Calls will be queued and automatically executed until the consent is available.
Step 1: Call this before initializing the SDK:
CleverPush.shared.setTrackingConsentRequired(true);
Step 2: Call this when the user gave his consent (needs to be called on every launch):
CleverPush.shared.setTrackingConsent(true);