@@ -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 () {
@@ -179,7 +179,7 @@ class OneSignal {
179
179
/// waiting for this request to complete.
180
180
Future <Map <String , dynamic >> sendTags (Map <String , dynamic > tags) async {
181
181
Map <dynamic , dynamic > response =
182
- await _tagsChannel.invokeMethod ("OneSignal#sendTags" , tags);
182
+ await ( _tagsChannel.invokeMethod ("OneSignal#sendTags" , tags) );
183
183
return response.cast <String , dynamic >();
184
184
}
185
185
@@ -190,7 +190,7 @@ class OneSignal {
190
190
/// to finish.
191
191
Future <Map <String , dynamic >> getTags () async {
192
192
Map <dynamic , dynamic > tags =
193
- await _tagsChannel.invokeMethod ("OneSignal#getTags" );
193
+ await ( _tagsChannel.invokeMethod ("OneSignal#getTags" ) );
194
194
return tags.cast <String , dynamic >();
195
195
}
196
196
@@ -207,15 +207,18 @@ class OneSignal {
207
207
/// array of keys.
208
208
Future <Map <String , dynamic >> deleteTags (List <String > keys) async {
209
209
Map <dynamic , dynamic > response =
210
- await _tagsChannel.invokeMethod ("OneSignal#deleteTags" , keys);
210
+ await ( _tagsChannel.invokeMethod ("OneSignal#deleteTags" , keys) );
211
211
return response.cast <String , dynamic >();
212
212
}
213
213
214
214
/// Returns an `OSDeviceState` object, which contains the current device state
215
- Future <OSDeviceState > getDeviceState () async {
215
+ Future <OSDeviceState ? > getDeviceState () async {
216
216
var json =
217
217
await _channel.invokeMethod ("OneSignal#getDeviceState" );
218
218
219
+ if ((json.cast <String , dynamic >()).isEmpty)
220
+ return null ;
221
+
219
222
return OSDeviceState (json.cast <String , dynamic >());
220
223
}
221
224
@@ -232,14 +235,14 @@ class OneSignal {
232
235
Future <Map <String , dynamic >> postNotificationWithJson (
233
236
Map <String , dynamic > json) async {
234
237
Map <dynamic , dynamic > response =
235
- await _channel.invokeMethod ("OneSignal#postNotification" , json);
238
+ await ( _channel.invokeMethod ("OneSignal#postNotification" , json) );
236
239
return response.cast <String , dynamic >();
237
240
}
238
241
239
242
Future <Map <String , dynamic >> postNotification (
240
243
OSCreateNotification notification) async {
241
- Map <dynamic , dynamic > response = await _channel.invokeMethod (
242
- "OneSignal#postNotification" , notification.mapRepresentation ());
244
+ Map <dynamic , dynamic > response = await ( _channel.invokeMethod (
245
+ "OneSignal#postNotification" , notification.mapRepresentation ())) ;
243
246
return response.cast <String , dynamic >();
244
247
}
245
248
@@ -270,7 +273,7 @@ class OneSignal {
270
273
/// Identity Verification. The email auth hash is a hash of your app's API key and the
271
274
/// user ID. We recommend you generate this token from your backend server, do NOT
272
275
/// store your API key in your app as this is highly insecure.
273
- Future <void > setEmail ({String email, String emailAuthHashToken}) async {
276
+ Future <void > setEmail ({required String email, String ? emailAuthHashToken}) async {
274
277
return await _channel.invokeMethod ("OneSignal#setEmail" ,
275
278
{'email' : email, 'emailAuthHashToken' : emailAuthHashToken});
276
279
}
@@ -284,16 +287,16 @@ class OneSignal {
284
287
/// OneSignal allows you to set a custom ID for your users. This makes it so that
285
288
/// if your app has its own user ID's, you can use your own custom user ID's with
286
289
/// our API instead of having to save their OneSignal user ID's.
287
- Future <Map <String , dynamic >> setExternalUserId (String externalId, [String authHashToken]) async {
290
+ Future <Map <String , dynamic >> setExternalUserId (String externalId, [String ? authHashToken]) async {
288
291
Map <dynamic , dynamic > results =
289
- await _channel.invokeMethod ("OneSignal#setExternalUserId" , {'externalUserId' : externalId, 'authHashToken' : authHashToken});
292
+ await ( _channel.invokeMethod ("OneSignal#setExternalUserId" , {'externalUserId' : externalId, 'authHashToken' : authHashToken}) );
290
293
return results.cast <String , dynamic >();
291
294
}
292
295
293
296
/// Removes the external user ID that was set for the current user.
294
297
Future <Map <String , dynamic >> removeExternalUserId () async {
295
298
Map <dynamic , dynamic > results =
296
- await _channel.invokeMethod ("OneSignal#removeExternalUserId" );
299
+ await ( _channel.invokeMethod ("OneSignal#removeExternalUserId" ) );
297
300
return results.cast <String , dynamic >();
298
301
}
299
302
@@ -322,7 +325,7 @@ class OneSignal {
322
325
}
323
326
324
327
/// Get the trigger value associated with the key provided
325
- Future <Object > getTriggerValueForKey (String key) async {
328
+ Future <Object ? > getTriggerValueForKey (String key) async {
326
329
return await _inAppMessagesChannel.invokeMethod ("OneSignal#getTriggerValueForKey" , key);
327
330
}
328
331
@@ -368,27 +371,27 @@ class OneSignal {
368
371
Future <Null > _handleMethod (MethodCall call) async {
369
372
if (call.method == 'OneSignal#handleOpenedNotification' &&
370
373
this ._onOpenedNotification != null ) {
371
- this ._onOpenedNotification (
374
+ this ._onOpenedNotification ! (
372
375
OSNotificationOpenedResult (call.arguments.cast <String , dynamic >()));
373
376
} else if (call.method == 'OneSignal#subscriptionChanged' &&
374
377
this ._onSubscriptionChangedHandler != null ) {
375
- this ._onSubscriptionChangedHandler (
378
+ this ._onSubscriptionChangedHandler ! (
376
379
OSSubscriptionStateChanges (call.arguments.cast <String , dynamic >()));
377
380
} else if (call.method == 'OneSignal#permissionChanged' &&
378
381
this ._onPermissionChangedHandler != null ) {
379
- this ._onPermissionChangedHandler (
382
+ this ._onPermissionChangedHandler ! (
380
383
OSPermissionStateChanges (call.arguments.cast <String , dynamic >()));
381
384
} else if (call.method == 'OneSignal#emailSubscriptionChanged' &&
382
385
this ._onEmailSubscriptionChangedHandler != null ) {
383
- this ._onEmailSubscriptionChangedHandler (
386
+ this ._onEmailSubscriptionChangedHandler ! (
384
387
OSEmailSubscriptionStateChanges (call.arguments.cast <String , dynamic >()));
385
388
} else if (call.method == 'OneSignal#handleClickedInAppMessage' &&
386
389
this ._onInAppMessageClickedHandler != null ) {
387
- this ._onInAppMessageClickedHandler (
390
+ this ._onInAppMessageClickedHandler ! (
388
391
OSInAppMessageAction (call.arguments.cast <String , dynamic >()));
389
392
} else if (call.method == 'OneSignal#handleNotificationWillShowInForeground' &&
390
393
this ._onNotificationWillShowInForegroundHandler != null ) {
391
- this ._onNotificationWillShowInForegroundHandler (
394
+ this ._onNotificationWillShowInForegroundHandler ! (
392
395
OSNotificationReceivedEvent (call.arguments.cast <String , dynamic >()));
393
396
}
394
397
return null ;
0 commit comments