initPlatformState method
Implementation
Future initPlatformState() async {
try {
OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
OneSignal.initialize(admodel?.oneSignalApp ?? '');
OneSignal.Notifications.requestPermission(true);
OneSignal.Debug.setLogLevel(OSLogLevel.none);
await OneSignal.consentRequired(_requireConsent);
await OneSignal.LiveActivities.setupDefault();
await OneSignal.Notifications.clearAll();
await OneSignal.Notifications.lifecycleInit();
OneSignal.Notifications.addClickListener((event) {
},);
OneSignal.Notifications.registerForProvisionalAuthorization(true);
await OneSignal.Notifications.canRequest();
OneSignal.User.pushSubscription.addObserver((state) {
print(OneSignal.User.pushSubscription.optedIn);
print(OneSignal.User.pushSubscription.id);
print(OneSignal.User.pushSubscription.token);
print(state.current.jsonRepresentation());
});
OneSignal.User.addObserver((state) {
var userState = state.jsonRepresentation();
print('OneSignal user changed: $userState');
});
OneSignal.Notifications.addPermissionObserver((state) {
print("Has permission " + state.toString());
});
OneSignal.Notifications.addClickListener((event) {
print('NOTIFICATION CLICK LISTENER CALLED WITH EVENT: $event');
});
OneSignal.Notifications.addForegroundWillDisplayListener((event) {
print(
'NOTIFICATION WILL DISPLAY LISTENER CALLED WITH: ${event
.notification
.jsonRepresentation()}');
/// Display Notification, preventDefault to not display
event.preventDefault();
/// Do async work
/// notification.display() to display after preventing default
event.notification.display();
});
_enableConsentButton = _requireConsent;
OneSignal.InAppMessages.paused(false);
var canRequestAds = await ConsentManager.instance.canRequestAds();
if (!canRequestAds) {
return;
}
} catch (e) {
if (kDebugMode) {
print(e);
}
}
}