Skip to content

Commit ab924fe

Browse files
committed
Add Dart IAM Lifecycle Implementation
* Add IAM Lifecycle implementation to onesignal dart * Add OSInAppMessage to JSON representation in in_app_message dart file
1 parent 23f41ff commit ab924fe

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

lib/onesignal_flutter.dart

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ typedef void EmailSubscriptionChangeHandler(OSEmailSubscriptionStateChanges chan
2525
typedef void SMSSubscriptionChangeHandler(OSSMSSubscriptionStateChanges changes);
2626
typedef void PermissionChangeHandler(OSPermissionStateChanges changes);
2727
typedef void InAppMessageClickedHandler(OSInAppMessageAction action);
28+
typedef void OnWillDisplayInAppMessageHandler(OSInAppMessage message);
29+
typedef void OnDidDisplayInAppMessageHandler(OSInAppMessage message);
30+
typedef void OnWillDismissInAppMessageHandler(OSInAppMessage message);
31+
typedef void OnDidDismissInAppMessageHandler(OSInAppMessage message);
2832
typedef void NotificationWillShowInForegroundHandler(OSNotificationReceivedEvent event);
2933

3034
class OneSignal {
@@ -47,6 +51,10 @@ class OneSignal {
4751
SMSSubscriptionChangeHandler? _onSMSSubscriptionChangedHandler;
4852
PermissionChangeHandler? _onPermissionChangedHandler;
4953
InAppMessageClickedHandler? _onInAppMessageClickedHandler;
54+
OnWillDisplayInAppMessageHandler? _onWillDisplayInAppMessageHandler;
55+
OnDidDisplayInAppMessageHandler? _onDidDisplayInAppMessageHandler;
56+
OnWillDismissInAppMessageHandler? _onWillDismissInAppMessageHandler;
57+
OnDidDismissInAppMessageHandler? _onDidDismissInAppMessageHandler;
5058
NotificationWillShowInForegroundHandler? _onNotificationWillShowInForegroundHandler;
5159

5260
// constructor method
@@ -114,6 +122,34 @@ class OneSignal {
114122
_channel.invokeMethod("OneSignal#initInAppMessageClickedHandlerParams");
115123
}
116124

125+
/// The in app message will display handler is called whenever the in app message
126+
/// is about to be displayed
127+
void setOnWillDisplayInAppMessageHandler(OnWillDisplayInAppMessageHandler handler) {
128+
_onWillDisplayInAppMessageHandler = handler;
129+
_channel.invokeMethod("OneSignal#onWillDisplayInAppMessageHandlerParams");
130+
}
131+
132+
/// The in app message did display handler is called whenever the in app message
133+
/// is displayed
134+
void setOnDidDisplayInAppMessageHandler(OnDidDisplayInAppMessageHandler handler) {
135+
_onDidDisplayInAppMessageHandler = handler;
136+
_channel.invokeMethod("OneSignal#onDidDisplayInAppMessageHandlerParams");
137+
}
138+
139+
/// The in app message will dismiss handler is called whenever the in app message
140+
/// is about to be dismissed
141+
void setOnWillDismissInAppMessageHandler(OnWillDismissInAppMessageHandler handler) {
142+
_onWillDismissInAppMessageHandler = handler;
143+
_channel.invokeMethod("OneSignal#onWillDismissInAppMessageHandlerParams");
144+
}
145+
146+
/// The in app message did dismiss handler is called whenever the in app message
147+
/// is dismissed
148+
void setOnDidDismissInAppMessageHandler(OnDidDismissInAppMessageHandler handler) {
149+
_onDidDismissInAppMessageHandler = handler;
150+
_channel.invokeMethod("OneSignal#onDidDismissInAppMessageHandlerParams");
151+
}
152+
117153
/// The notification foreground handler is called whenever a notification arrives
118154
/// and the application is in foreground
119155
void setNotificationWillShowInForegroundHandler(NotificationWillShowInForegroundHandler handler) {
@@ -428,6 +464,22 @@ class OneSignal {
428464
this._onInAppMessageClickedHandler != null) {
429465
this._onInAppMessageClickedHandler!(
430466
OSInAppMessageAction(call.arguments.cast<String, dynamic>()));
467+
} else if (call.method == 'OneSignal#onWillDisplayInAppMessage' &&
468+
this._onWillDisplayInAppMessageHandler != null) {
469+
this._onWillDisplayInAppMessageHandler!(
470+
OSInAppMessage(call.arguments.cast<String, dynamic>()));
471+
} else if (call.method == 'OneSignal#onDidDisplayInAppMessage' &&
472+
this._onDidDisplayInAppMessageHandler != null) {
473+
this._onDidDisplayInAppMessageHandler!(
474+
OSInAppMessage(call.arguments.cast<String, dynamic>()));
475+
} else if (call.method == 'OneSignal#onWillDismissInAppMessage' &&
476+
this._onWillDismissInAppMessageHandler != null) {
477+
this._onWillDismissInAppMessageHandler!(
478+
OSInAppMessage(call.arguments.cast<String, dynamic>()));
479+
} else if (call.method == 'OneSignal#onDidDismissInAppMessage' &&
480+
this._onDidDismissInAppMessageHandler != null) {
481+
this._onDidDismissInAppMessageHandler!(
482+
OSInAppMessage(call.arguments.cast<String, dynamic>()));
431483
} else if (call.method == 'OneSignal#handleNotificationWillShowInForeground' &&
432484
this._onNotificationWillShowInForegroundHandler != null) {
433485
this._onNotificationWillShowInForegroundHandler!(

lib/src/in_app_message.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,17 @@ class OSInAppMessageAction extends JSONStringRepresentable {
3434
}
3535

3636
}
37+
38+
class OSInAppMessage extends JSONStringRepresentable {
39+
String? messageId;
40+
41+
OSInAppMessage(Map<String, dynamic> json) {
42+
this.messageId = json["message_id"];
43+
}
44+
45+
String jsonRepresentation() {
46+
return convertToJsonString({
47+
'message_id': this.messageId
48+
});
49+
}
50+
}

0 commit comments

Comments
 (0)