@@ -22,15 +22,18 @@ export 'src/outcome_event.dart';
22
22
typedef void ReceivedNotificationHandler (OSNotification notification);
23
23
typedef void OpenedNotificationHandler (OSNotificationOpenedResult openedResult);
24
24
typedef void SubscriptionChangedHandler (OSSubscriptionStateChanges changes);
25
- typedef void EmailSubscriptionChangeHandler (OSEmailSubscriptionStateChanges changes);
26
- typedef void SMSSubscriptionChangeHandler (OSSMSSubscriptionStateChanges changes);
25
+ typedef void EmailSubscriptionChangeHandler (
26
+ OSEmailSubscriptionStateChanges changes);
27
+ typedef void SMSSubscriptionChangeHandler (
28
+ OSSMSSubscriptionStateChanges changes);
27
29
typedef void PermissionChangeHandler (OSPermissionStateChanges changes);
28
30
typedef void InAppMessageClickedHandler (OSInAppMessageAction action);
29
31
typedef void OnWillDisplayInAppMessageHandler (OSInAppMessage message);
30
32
typedef void OnDidDisplayInAppMessageHandler (OSInAppMessage message);
31
33
typedef void OnWillDismissInAppMessageHandler (OSInAppMessage message);
32
34
typedef void OnDidDismissInAppMessageHandler (OSInAppMessage message);
33
- typedef void NotificationWillShowInForegroundHandler (OSNotificationReceivedEvent event);
35
+ typedef void NotificationWillShowInForegroundHandler (
36
+ OSNotificationReceivedEvent event);
34
37
35
38
class OneSignal {
36
39
/// A singleton representing the OneSignal SDK.
@@ -42,7 +45,8 @@ class OneSignal {
42
45
// private channels used to bridge to ObjC/Java
43
46
MethodChannel _channel = const MethodChannel ('OneSignal' );
44
47
MethodChannel _tagsChannel = const MethodChannel ('OneSignal#tags' );
45
- MethodChannel _inAppMessagesChannel = const MethodChannel ('OneSignal#inAppMessages' );
48
+ MethodChannel _inAppMessagesChannel =
49
+ const MethodChannel ('OneSignal#inAppMessages' );
46
50
MethodChannel _outcomesChannel = const MethodChannel ('OneSignal#outcomes' );
47
51
48
52
// event handlers
@@ -56,7 +60,8 @@ class OneSignal {
56
60
OnDidDisplayInAppMessageHandler ? _onDidDisplayInAppMessageHandler;
57
61
OnWillDismissInAppMessageHandler ? _onWillDismissInAppMessageHandler;
58
62
OnDidDismissInAppMessageHandler ? _onDidDismissInAppMessageHandler;
59
- NotificationWillShowInForegroundHandler ? _onNotificationWillShowInForegroundHandler;
63
+ NotificationWillShowInForegroundHandler ?
64
+ _onNotificationWillShowInForegroundHandler;
60
65
61
66
// constructor method
62
67
OneSignal () {
@@ -69,8 +74,7 @@ class OneSignal {
69
74
_onesignalLog (OSLogLevel .verbose,
70
75
"Initializing the OneSignal Flutter SDK ($sdkVersion )" );
71
76
72
- await _channel.invokeMethod (
73
- 'OneSignal#setAppId' , {'appId' : appId});
77
+ await _channel.invokeMethod ('OneSignal#setAppId' , {'appId' : appId});
74
78
}
75
79
76
80
/// Sets the log level for the SDK. The first parameter (logLevel) controls
@@ -153,9 +157,11 @@ class OneSignal {
153
157
154
158
/// The notification foreground handler is called whenever a notification arrives
155
159
/// and the application is in foreground
156
- void setNotificationWillShowInForegroundHandler (NotificationWillShowInForegroundHandler handler) {
160
+ void setNotificationWillShowInForegroundHandler (
161
+ NotificationWillShowInForegroundHandler handler) {
157
162
_onNotificationWillShowInForegroundHandler = handler;
158
- _channel.invokeMethod ("OneSignal#initNotificationWillShowInForegroundHandlerParams" );
163
+ _channel.invokeMethod (
164
+ "OneSignal#initNotificationWillShowInForegroundHandlerParams" );
159
165
}
160
166
161
167
/// The notification foreground handler is called whenever a notification arrives
@@ -171,7 +177,7 @@ class OneSignal {
171
177
Future <void > setLaunchURLsInApp (bool isEnabled) async {
172
178
if (Platform .isIOS) {
173
179
await _channel.invokeMethod (
174
- "OneSignal#setLaunchURLsInApp" , {'isEnabled' : isEnabled});
180
+ "OneSignal#setLaunchURLsInApp" , {'isEnabled' : isEnabled});
175
181
} else {
176
182
_onesignalLog (OSLogLevel .info,
177
183
"setLaunchURLsInApp: this function is not supported on Android" );
@@ -274,11 +280,9 @@ class OneSignal {
274
280
275
281
/// Returns an `OSDeviceState` object, which contains the current device state
276
282
Future <OSDeviceState ?> getDeviceState () async {
277
- var json =
278
- await _channel.invokeMethod ("OneSignal#getDeviceState" );
283
+ var json = await _channel.invokeMethod ("OneSignal#getDeviceState" );
279
284
280
- if ((json.cast <String , dynamic >()).isEmpty)
281
- return null ;
285
+ if ((json.cast <String , dynamic >()).isEmpty) return null ;
282
286
283
287
return OSDeviceState (json.cast <String , dynamic >());
284
288
}
@@ -314,8 +318,8 @@ class OneSignal {
314
318
315
319
/// Allows you to manually cancel a single OneSignal notification based on its Android notification integer ID
316
320
void removeNotification (int notificationId) {
317
- _channel.invokeMethod ("OneSignal#removeNotification" ,
318
- {'notificationId' : notificationId});
321
+ _channel.invokeMethod (
322
+ "OneSignal#removeNotification" , {'notificationId' : notificationId});
319
323
}
320
324
321
325
/// Allows you to prompt the user for permission to use location services
@@ -334,7 +338,8 @@ class OneSignal {
334
338
/// Identity Verification. The email auth hash is a hash of your app's API key and the
335
339
/// user ID. We recommend you generate this token from your backend server, do NOT
336
340
/// store your API key in your app as this is highly insecure.
337
- Future <void > setEmail ({required String email, String ? emailAuthHashToken}) async {
341
+ Future <void > setEmail (
342
+ {required String email, String ? emailAuthHashToken}) async {
338
343
return await _channel.invokeMethod ("OneSignal#setEmail" ,
339
344
{'email' : email, 'emailAuthHashToken' : emailAuthHashToken});
340
345
}
@@ -350,9 +355,11 @@ class OneSignal {
350
355
/// Identity Verification. The SMS auth hash is a hash of your app's API key and the
351
356
/// user ID. We recommend you generate this token from your backend server, do NOT
352
357
/// store your API key in your app as this is highly insecure.
353
- Future <Map <String , dynamic >> setSMSNumber ({required String smsNumber, String ? smsAuthHashToken}) async {
354
- Map <dynamic , dynamic > results =
355
- await _channel.invokeMethod ("OneSignal#setSMSNumber" , {'smsNumber' : smsNumber, 'smsAuthHashToken' : smsAuthHashToken});
358
+ Future <Map <String , dynamic >> setSMSNumber (
359
+ {required String smsNumber, String ? smsAuthHashToken}) async {
360
+ Map <dynamic , dynamic > results = await _channel.invokeMethod (
361
+ "OneSignal#setSMSNumber" ,
362
+ {'smsNumber' : smsNumber, 'smsAuthHashToken' : smsAuthHashToken});
356
363
return results.cast <String , dynamic >();
357
364
}
358
365
@@ -367,9 +374,11 @@ class OneSignal {
367
374
/// OneSignal allows you to set a custom ID for your users. This makes it so that
368
375
/// if your app has its own user ID's, you can use your own custom user ID's with
369
376
/// our API instead of having to save their OneSignal user ID's.
370
- Future <Map <String , dynamic >> setExternalUserId (String externalId, [String ? authHashToken]) async {
371
- Map <dynamic , dynamic > results =
372
- await (_channel.invokeMethod ("OneSignal#setExternalUserId" , {'externalUserId' : externalId, 'authHashToken' : authHashToken}));
377
+ Future <Map <String , dynamic >> setExternalUserId (String externalId,
378
+ [String ? authHashToken]) async {
379
+ Map <dynamic , dynamic > results = await (_channel.invokeMethod (
380
+ "OneSignal#setExternalUserId" ,
381
+ {'externalUserId' : externalId, 'authHashToken' : authHashToken}));
373
382
return results.cast <String , dynamic >();
374
383
}
375
384
@@ -383,74 +392,81 @@ class OneSignal {
383
392
/// Sets the user's language.
384
393
/// Applies also to the email and/or SMS player if those are logged in on the device.
385
394
Future <Map <String , dynamic >> setLanguage (String language) async {
386
- Map <dynamic , dynamic > results =
387
- await (_channel .invokeMethod ("OneSignal#setLanguage" , {'language' : language}));
395
+ Map <dynamic , dynamic > results = await (_channel
396
+ .invokeMethod ("OneSignal#setLanguage" , {'language' : language}));
388
397
return results.cast <String , dynamic >();
389
398
}
390
399
391
400
/// Adds a single key, value trigger, which will trigger an in app message
392
401
/// if one exists matching the specific trigger added
393
402
Future <void > addTrigger (String key, Object value) async {
394
- return await _inAppMessagesChannel.invokeMethod ("OneSignal#addTrigger" , {key : value});
403
+ return await _inAppMessagesChannel
404
+ .invokeMethod ("OneSignal#addTrigger" , {key: value});
395
405
}
396
406
397
407
/// Adds one or more key, value triggers, which will trigger in app messages
398
408
/// (one at a time) if any exist matching the specific triggers added
399
409
Future <void > addTriggers (Map <String , Object > triggers) async {
400
- return await _inAppMessagesChannel.invokeMethod ("OneSignal#addTriggers" , triggers);
410
+ return await _inAppMessagesChannel.invokeMethod (
411
+ "OneSignal#addTriggers" , triggers);
401
412
}
402
413
403
414
/// Remove a single key, value trigger to prevent an in app message from
404
415
/// showing with that trigger
405
416
Future <void > removeTriggerForKey (String key) async {
406
- return await _inAppMessagesChannel.invokeMethod ("OneSignal#removeTriggerForKey" , key);
417
+ return await _inAppMessagesChannel.invokeMethod (
418
+ "OneSignal#removeTriggerForKey" , key);
407
419
}
408
420
409
421
/// Remove one or more key, value triggers to prevent any in app messages
410
422
/// from showing with those triggers
411
423
Future <void > removeTriggersForKeys (List <String > keys) async {
412
- return await _inAppMessagesChannel.invokeMethod ("OneSignal#removeTriggersForKeys" , keys);
424
+ return await _inAppMessagesChannel.invokeMethod (
425
+ "OneSignal#removeTriggersForKeys" , keys);
413
426
}
414
427
415
428
/// Get the trigger value associated with the key provided
416
429
Future <Object ?> getTriggerValueForKey (String key) async {
417
- return await _inAppMessagesChannel.invokeMethod ("OneSignal#getTriggerValueForKey" , key);
430
+ return await _inAppMessagesChannel.invokeMethod (
431
+ "OneSignal#getTriggerValueForKey" , key);
418
432
}
419
433
420
434
/// Toggles the showing of all in app messages
421
435
Future <void > pauseInAppMessages (bool pause) async {
422
- return await _inAppMessagesChannel.invokeMethod ("OneSignal#pauseInAppMessages" , pause);
436
+ return await _inAppMessagesChannel.invokeMethod (
437
+ "OneSignal#pauseInAppMessages" , pause);
423
438
}
424
439
425
440
/// Send a normal outcome event for the current session and notifications with the attribution window
426
441
/// Counted each time sent successfully, failed ones will be cached and reattempted in future
427
442
Future <OSOutcomeEvent > sendOutcome (String name) async {
428
- var json = await _outcomesChannel.invokeMethod ("OneSignal#sendOutcome" , name);
443
+ var json =
444
+ await _outcomesChannel.invokeMethod ("OneSignal#sendOutcome" , name);
429
445
430
- if (json == null )
431
- return new OSOutcomeEvent ();
446
+ if (json == null ) return new OSOutcomeEvent ();
432
447
433
448
return new OSOutcomeEvent .fromMap (json.cast <String , dynamic >());
434
449
}
435
450
436
451
/// Send a unique outcome event for the current session and notifications with the attribution window
437
452
/// Counted once per notification when sent successfully, failed ones will be cached and reattempted in future
438
453
Future <OSOutcomeEvent > sendUniqueOutcome (String name) async {
439
- var json = await _outcomesChannel.invokeMethod ("OneSignal#sendUniqueOutcome" , name);
454
+ var json = await _outcomesChannel.invokeMethod (
455
+ "OneSignal#sendUniqueOutcome" , name);
440
456
441
- if (json == null )
442
- return new OSOutcomeEvent ();
457
+ if (json == null ) return new OSOutcomeEvent ();
443
458
444
459
return new OSOutcomeEvent .fromMap (json.cast <String , dynamic >());
445
460
}
446
461
447
462
/// Send an outcome event with a value for the current session and notifications with the attribution window
448
463
/// Counted each time sent successfully, failed ones will be cached and reattempted in future
449
464
Future <OSOutcomeEvent > sendOutcomeWithValue (String name, double value) async {
450
- var json = await _outcomesChannel.invokeMethod ("OneSignal#sendOutcomeWithValue" , {"outcome_name" : name, "outcome_value" : value});
465
+ var json = await _outcomesChannel.invokeMethod (
466
+ "OneSignal#sendOutcomeWithValue" ,
467
+ {"outcome_name" : name, "outcome_value" : value});
451
468
452
- if (json == null )
453
- return new OSOutcomeEvent ();
469
+ if (json == null ) return new OSOutcomeEvent ();
454
470
455
471
return new OSOutcomeEvent .fromMap (json.cast <String , dynamic >());
456
472
}
@@ -468,15 +484,15 @@ class OneSignal {
468
484
} else if (call.method == 'OneSignal#permissionChanged' &&
469
485
this ._onPermissionChangedHandler != null ) {
470
486
this ._onPermissionChangedHandler !(
471
- OSPermissionStateChanges (call.arguments.cast <String , dynamic >()));
487
+ OSPermissionStateChanges (call.arguments.cast <String , dynamic >()));
472
488
} else if (call.method == 'OneSignal#emailSubscriptionChanged' &&
473
489
this ._onEmailSubscriptionChangedHandler != null ) {
474
- this ._onEmailSubscriptionChangedHandler !(
475
- OSEmailSubscriptionStateChanges ( call.arguments.cast <String , dynamic >()));
490
+ this ._onEmailSubscriptionChangedHandler !(OSEmailSubscriptionStateChanges (
491
+ call.arguments.cast <String , dynamic >()));
476
492
} else if (call.method == 'OneSignal#smsSubscriptionChanged' &&
477
493
this ._onSMSSubscriptionChangedHandler != null ) {
478
- this ._onSMSSubscriptionChangedHandler !(
479
- OSSMSSubscriptionStateChanges ( call.arguments.cast <String , dynamic >()));
494
+ this ._onSMSSubscriptionChangedHandler !(OSSMSSubscriptionStateChanges (
495
+ call.arguments.cast <String , dynamic >()));
480
496
} else if (call.method == 'OneSignal#handleClickedInAppMessage' &&
481
497
this ._onInAppMessageClickedHandler != null ) {
482
498
this ._onInAppMessageClickedHandler !(
@@ -497,7 +513,8 @@ class OneSignal {
497
513
this ._onDidDismissInAppMessageHandler != null ) {
498
514
this ._onDidDismissInAppMessageHandler !(
499
515
OSInAppMessage (call.arguments.cast <String , dynamic >()));
500
- } else if (call.method == 'OneSignal#handleNotificationWillShowInForeground' &&
516
+ } else if (call.method ==
517
+ 'OneSignal#handleNotificationWillShowInForeground' &&
501
518
this ._onNotificationWillShowInForegroundHandler != null ) {
502
519
this ._onNotificationWillShowInForegroundHandler !(
503
520
OSNotificationReceivedEvent (call.arguments.cast <String , dynamic >()));
@@ -514,7 +531,7 @@ class OneSignal {
514
531
Map <String , dynamic > _processSettings (Map <OSiOSSettings , dynamic > settings) {
515
532
var finalSettings = Map <String , dynamic >();
516
533
517
- if (settings == null ) return finalSettings;
534
+ if (settings.isEmpty ) return finalSettings;
518
535
519
536
for (OSiOSSettings key in settings.keys) {
520
537
var settingsKey = convertEnumCaseToValue (key);
0 commit comments