@@ -40,12 +40,12 @@ class OneSignal {
40
40
MethodChannel _outcomesChannel = const MethodChannel ('OneSignal#outcomes' );
41
41
42
42
// event handlers
43
- OpenedNotificationHandler _onOpenedNotification;
44
- SubscriptionChangedHandler _onSubscriptionChangedHandler;
45
- EmailSubscriptionChangeHandler _onEmailSubscriptionChangedHandler;
46
- PermissionChangeHandler _onPermissionChangedHandler;
47
- InAppMessageClickedHandler _onInAppMessageClickedHandler;
48
- NotificationWillShowInForegroundHandler _onNotificationWillShowInForegroundHandler;
43
+ OpenedNotificationHandler ? _onOpenedNotification;
44
+ SubscriptionChangedHandler ? _onSubscriptionChangedHandler;
45
+ EmailSubscriptionChangeHandler ? _onEmailSubscriptionChangedHandler;
46
+ PermissionChangeHandler ? _onPermissionChangedHandler;
47
+ InAppMessageClickedHandler ? _onInAppMessageClickedHandler;
48
+ NotificationWillShowInForegroundHandler ? _onNotificationWillShowInForegroundHandler;
49
49
50
50
// constructor method
51
51
OneSignal () {
@@ -155,12 +155,13 @@ class OneSignal {
155
155
}
156
156
157
157
/// in iOS, will prompt the user for permission to send push notifications.
158
+ // in Android, it will always return false, since notification permission is by default given
158
159
Future <bool > promptUserForPushNotificationPermission (
159
160
{bool fallbackToSettings = false }) async {
160
161
dynamic result = await _channel.invokeMethod (
161
162
"OneSignal#promptPermission" , {'fallback' : fallbackToSettings});
162
163
163
- return result as bool ;
164
+ return result as bool ? ?? false ;
164
165
}
165
166
166
167
/// Sends a single key/value pair to tags to OneSignal.
@@ -179,7 +180,7 @@ class OneSignal {
179
180
/// waiting for this request to complete.
180
181
Future <Map <String , dynamic >> sendTags (Map <String , dynamic > tags) async {
181
182
Map <dynamic , dynamic > response =
182
- await _tagsChannel.invokeMethod ("OneSignal#sendTags" , tags);
183
+ await ( _tagsChannel.invokeMethod ("OneSignal#sendTags" , tags) );
183
184
return response.cast <String , dynamic >();
184
185
}
185
186
@@ -190,7 +191,7 @@ class OneSignal {
190
191
/// to finish.
191
192
Future <Map <String , dynamic >> getTags () async {
192
193
Map <dynamic , dynamic > tags =
193
- await _tagsChannel.invokeMethod ("OneSignal#getTags" );
194
+ await ( _tagsChannel.invokeMethod ("OneSignal#getTags" ) );
194
195
return tags.cast <String , dynamic >();
195
196
}
196
197
@@ -207,15 +208,18 @@ class OneSignal {
207
208
/// array of keys.
208
209
Future <Map <String , dynamic >> deleteTags (List <String > keys) async {
209
210
Map <dynamic , dynamic > response =
210
- await _tagsChannel.invokeMethod ("OneSignal#deleteTags" , keys);
211
+ await ( _tagsChannel.invokeMethod ("OneSignal#deleteTags" , keys) );
211
212
return response.cast <String , dynamic >();
212
213
}
213
214
214
215
/// Returns an `OSDeviceState` object, which contains the current device state
215
- Future <OSDeviceState > getDeviceState () async {
216
+ Future <OSDeviceState ? > getDeviceState () async {
216
217
var json =
217
218
await _channel.invokeMethod ("OneSignal#getDeviceState" );
218
219
220
+ if ((json.cast <String , dynamic >()).isEmpty)
221
+ return null ;
222
+
219
223
return OSDeviceState (json.cast <String , dynamic >());
220
224
}
221
225
@@ -232,14 +236,14 @@ class OneSignal {
232
236
Future <Map <String , dynamic >> postNotificationWithJson (
233
237
Map <String , dynamic > json) async {
234
238
Map <dynamic , dynamic > response =
235
- await _channel.invokeMethod ("OneSignal#postNotification" , json);
239
+ await ( _channel.invokeMethod ("OneSignal#postNotification" , json) );
236
240
return response.cast <String , dynamic >();
237
241
}
238
242
239
243
Future <Map <String , dynamic >> postNotification (
240
244
OSCreateNotification notification) async {
241
- Map <dynamic , dynamic > response = await _channel.invokeMethod (
242
- "OneSignal#postNotification" , notification.mapRepresentation ());
245
+ Map <dynamic , dynamic > response = await ( _channel.invokeMethod (
246
+ "OneSignal#postNotification" , notification.mapRepresentation ())) ;
243
247
return response.cast <String , dynamic >();
244
248
}
245
249
@@ -270,7 +274,7 @@ class OneSignal {
270
274
/// Identity Verification. The email auth hash is a hash of your app's API key and the
271
275
/// user ID. We recommend you generate this token from your backend server, do NOT
272
276
/// store your API key in your app as this is highly insecure.
273
- Future <void > setEmail ({String email, String emailAuthHashToken}) async {
277
+ Future <void > setEmail ({required String email, String ? emailAuthHashToken}) async {
274
278
return await _channel.invokeMethod ("OneSignal#setEmail" ,
275
279
{'email' : email, 'emailAuthHashToken' : emailAuthHashToken});
276
280
}
@@ -284,16 +288,16 @@ class OneSignal {
284
288
/// OneSignal allows you to set a custom ID for your users. This makes it so that
285
289
/// if your app has its own user ID's, you can use your own custom user ID's with
286
290
/// our API instead of having to save their OneSignal user ID's.
287
- Future <Map <String , dynamic >> setExternalUserId (String externalId, [String authHashToken]) async {
291
+ Future <Map <String , dynamic >> setExternalUserId (String externalId, [String ? authHashToken]) async {
288
292
Map <dynamic , dynamic > results =
289
- await _channel.invokeMethod ("OneSignal#setExternalUserId" , {'externalUserId' : externalId, 'authHashToken' : authHashToken});
293
+ await ( _channel.invokeMethod ("OneSignal#setExternalUserId" , {'externalUserId' : externalId, 'authHashToken' : authHashToken}) );
290
294
return results.cast <String , dynamic >();
291
295
}
292
296
293
297
/// Removes the external user ID that was set for the current user.
294
298
Future <Map <String , dynamic >> removeExternalUserId () async {
295
299
Map <dynamic , dynamic > results =
296
- await _channel.invokeMethod ("OneSignal#removeExternalUserId" );
300
+ await ( _channel.invokeMethod ("OneSignal#removeExternalUserId" ) );
297
301
return results.cast <String , dynamic >();
298
302
}
299
303
@@ -322,7 +326,7 @@ class OneSignal {
322
326
}
323
327
324
328
/// Get the trigger value associated with the key provided
325
- Future <Object > getTriggerValueForKey (String key) async {
329
+ Future <Object ? > getTriggerValueForKey (String key) async {
326
330
return await _inAppMessagesChannel.invokeMethod ("OneSignal#getTriggerValueForKey" , key);
327
331
}
328
332
@@ -368,27 +372,27 @@ class OneSignal {
368
372
Future <Null > _handleMethod (MethodCall call) async {
369
373
if (call.method == 'OneSignal#handleOpenedNotification' &&
370
374
this ._onOpenedNotification != null ) {
371
- this ._onOpenedNotification (
375
+ this ._onOpenedNotification ! (
372
376
OSNotificationOpenedResult (call.arguments.cast <String , dynamic >()));
373
377
} else if (call.method == 'OneSignal#subscriptionChanged' &&
374
378
this ._onSubscriptionChangedHandler != null ) {
375
- this ._onSubscriptionChangedHandler (
379
+ this ._onSubscriptionChangedHandler ! (
376
380
OSSubscriptionStateChanges (call.arguments.cast <String , dynamic >()));
377
381
} else if (call.method == 'OneSignal#permissionChanged' &&
378
382
this ._onPermissionChangedHandler != null ) {
379
- this ._onPermissionChangedHandler (
383
+ this ._onPermissionChangedHandler ! (
380
384
OSPermissionStateChanges (call.arguments.cast <String , dynamic >()));
381
385
} else if (call.method == 'OneSignal#emailSubscriptionChanged' &&
382
386
this ._onEmailSubscriptionChangedHandler != null ) {
383
- this ._onEmailSubscriptionChangedHandler (
387
+ this ._onEmailSubscriptionChangedHandler ! (
384
388
OSEmailSubscriptionStateChanges (call.arguments.cast <String , dynamic >()));
385
389
} else if (call.method == 'OneSignal#handleClickedInAppMessage' &&
386
390
this ._onInAppMessageClickedHandler != null ) {
387
- this ._onInAppMessageClickedHandler (
391
+ this ._onInAppMessageClickedHandler ! (
388
392
OSInAppMessageAction (call.arguments.cast <String , dynamic >()));
389
393
} else if (call.method == 'OneSignal#handleNotificationWillShowInForeground' &&
390
394
this ._onNotificationWillShowInForegroundHandler != null ) {
391
- this ._onNotificationWillShowInForegroundHandler (
395
+ this ._onNotificationWillShowInForegroundHandler ! (
392
396
OSNotificationReceivedEvent (call.arguments.cast <String , dynamic >()));
393
397
}
394
398
return null ;
0 commit comments