1
- import 'package:onesignal_flutter/src/defines.dart' ;
2
1
import 'package:onesignal_flutter/src/utils.dart' ;
3
2
import 'package:onesignal_flutter/onesignal_flutter.dart' ;
4
- import 'package:flutter/foundation.dart' ;
5
3
import 'dart:convert' ;
6
4
7
5
/// A class representing the notification, including the
8
6
/// payload of the notification as well as additional
9
7
/// parameters (such as whether the notification was `shown`
10
8
/// to the user, whether it's `silent` , etc.)
11
9
class OSNotification extends JSONStringRepresentable {
12
-
13
10
/// The OneSignal notification ID for this notification
14
11
late String notificationId;
15
12
@@ -188,8 +185,7 @@ class OSNotification extends JSONStringRepresentable {
188
185
this .mutableContent = json['mutableContent' ] as bool ? ;
189
186
if (json.containsKey ('category' ))
190
187
this .category = json['category' ] as String ? ;
191
- if (json.containsKey ('badge' ))
192
- this .badge = json['badge' ] as int ? ;
188
+ if (json.containsKey ('badge' )) this .badge = json['badge' ] as int ? ;
193
189
if (json.containsKey ('badgeIncrement' ))
194
190
this .badgeIncrement = json['badgeIncrement' ] as int ? ;
195
191
if (json.containsKey ('subtitle' ))
@@ -222,8 +218,7 @@ class OSNotification extends JSONStringRepresentable {
222
218
this .fromProjectNumber = json['fromProjectNumber' ] as String ? ;
223
219
if (json.containsKey ("collapseId" ))
224
220
this .collapseId = json['collapseId' ] as String ? ;
225
- if (json.containsKey ("priority" ))
226
- this .priority = json['priority' ] as int ? ;
221
+ if (json.containsKey ("priority" )) this .priority = json['priority' ] as int ? ;
227
222
if (json.containsKey ("androidNotificationId" ))
228
223
this .androidNotificationId = json['androidNotificationId' ] as int ? ;
229
224
if (json.containsKey ('backgroundImageLayout' )) {
@@ -232,24 +227,23 @@ class OSNotification extends JSONStringRepresentable {
232
227
}
233
228
if (json.containsKey ('groupedNotifications' )) {
234
229
final dynamic jsonGroupedNotifications = json['groupedNotifications' ];
235
- final jsonList = jsonDecode (jsonGroupedNotifications.toString ()) as List <dynamic >;
236
- this .groupedNotifications = jsonList.map ((dynamic item) =>
237
- OSNotification (item as Map <String , dynamic >)).toList ();
230
+ final jsonList =
231
+ jsonDecode (jsonGroupedNotifications.toString ()) as List <dynamic >;
232
+ this .groupedNotifications = jsonList
233
+ .map ((dynamic item) => OSNotification (item as Map <String , dynamic >))
234
+ .toList ();
238
235
}
239
-
236
+
240
237
// shared parameters
241
238
this .notificationId = json['notificationId' ] as String ;
242
239
243
240
if (json.containsKey ('templateName' ))
244
241
this .templateName = json['templateName' ] as String ? ;
245
242
if (json.containsKey ('templateId' ))
246
243
this .templateId = json['templateId' ] as String ? ;
247
- if (json.containsKey ('sound' ))
248
- this .sound = json['sound' ] as String ? ;
249
- if (json.containsKey ('title' ))
250
- this .title = json['title' ] as String ? ;
251
- if (json.containsKey ('body' ))
252
- this .body = json['body' ] as String ? ;
244
+ if (json.containsKey ('sound' )) this .sound = json['sound' ] as String ? ;
245
+ if (json.containsKey ('title' )) this .title = json['title' ] as String ? ;
246
+ if (json.containsKey ('body' )) this .body = json['body' ] as String ? ;
253
247
if (json.containsKey ('launchUrl' ))
254
248
this .launchUrl = json['launchUrl' ] as String ? ;
255
249
if (json.containsKey ('additionalData' ))
@@ -382,25 +376,25 @@ class OSAndroidBackgroundImageLayout extends JSONStringRepresentable {
382
376
}
383
377
384
378
class OSNotificationReceivedEvent extends JSONStringRepresentable {
385
-
386
379
late OSNotification notification;
387
380
388
381
OSNotificationReceivedEvent (Map <String , dynamic > json) {
389
382
notification = OSNotification (json);
390
383
}
391
384
392
385
void complete (OSNotification ? notification) {
393
- print ('OSNotificationReceivedEvent complete with notification: $notification ' );
386
+ print (
387
+ 'OSNotificationReceivedEvent complete with notification: $notification ' );
394
388
if (notification != null ) {
395
- OneSignal .shared.completeNotification (notification.notificationId, true );
389
+ OneSignal .shared.completeNotification (notification.notificationId, true );
396
390
} else {
397
- OneSignal .shared.completeNotification (this .notification.notificationId, false );
391
+ OneSignal .shared
392
+ .completeNotification (this .notification.notificationId, false );
398
393
}
399
394
}
400
395
401
396
String jsonRepresentation () {
402
- return convertToJsonString ({
403
- 'notification' : this .notification.jsonRepresentation ()
404
- });
397
+ return convertToJsonString (
398
+ {'notification' : this .notification.jsonRepresentation ()});
405
399
}
406
- }
400
+ }
0 commit comments