This is a reference guide to updating your application through breaking changes in the push package.
Similar to breaking changes in v2, listening to new tokens uses a callback based API. This removes the usage of streams completely from the API, opting for a simpler, callback API.
final onNewTokenSubscription = Push.instance.onNewToken.listen((token) {
print("Just got a new token: $token");
});
final onNotificationTapSubscription =
Push.instance.onNotificationTap.listen((data) {
print('Notification was tapped:\n'
'Data: $data \n');
tappedNotificationPayloads.value += [data];
});
// Unsubscribe with:
onNewTokenSubscription.cancel();
onNotificationTapSubscription.cancel();
final unsubscribeOnNewToken = Push.instance.addOnNewToken((token) {
print("Just got a new token: $token");
});
final onNotificationTapSubscription =
Push.instance.addOnNotificationTap((data) {
print('Notification was tapped:\n'
'Data: $data \n');
tappedNotificationPayloads.value += [data];
});
// Unsubscribe with:
unsubscribeOnNewToken();
unsubscribeOnNotificationTap();
There were breaking changes introduced in v2. See how to migrate from v1.
The stream API has been replaced with a Callback API.
Push.instance.onMessage.listen((message) { /* do something with message */ });
Push.instance.onBackgroundMessage.listen((message) { /* do something with message */ });
final unsubscribeOnMessage = Push.instance.addOnMessage((message) { /* do something with message */ });
final unsubscribeOnBackgroundMessage = Push.instance.addOnBackgroundMessage((message) { /* do something with message */ });
// Unsubscribe when it makes sense
unsubscribeOnMessage();
unsubscribeOnBackgroundMessage();