-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
mappers.dart
84 lines (76 loc) · 2.9 KB
/
mappers.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import 'package:flutter/foundation.dart';
import 'initialization_settings.dart';
import 'notification_action.dart';
import 'notification_attachment.dart';
import 'notification_category.dart';
import 'notification_details.dart';
// ignore_for_file: public_member_api_docs
extension DarwinNotificationActionMapper on DarwinNotificationAction {
Map<String, Object> toMap() => <String, Object>{
'identifier': identifier,
'title': title,
'options': options
.map((e) => 1 << e.index) // ignore: always_specify_types
.toList(),
'type': describeEnum(type),
if (buttonTitle != null) 'buttonTitle': buttonTitle!,
if (placeholder != null) 'placeholder': placeholder!,
};
}
extension DarwinNotificationCategoryMapper on DarwinNotificationCategory {
Map<String, Object> toMap() => <String, Object>{
'identifier': identifier,
'actions': actions
.map((e) => e.toMap()) // ignore: always_specify_types
.toList(),
'options': options
.map((e) => 1 << e.index) // ignore: always_specify_types
.toList(),
};
}
extension DarwinInitializationSettingsMapper on DarwinInitializationSettings {
Map<String, Object> toMap() => <String, Object>{
'requestAlertPermission': requestAlertPermission,
'requestSoundPermission': requestSoundPermission,
'requestBadgePermission': requestBadgePermission,
'requestCriticalPermission': requestCriticalPermission,
'defaultPresentAlert': defaultPresentAlert,
'defaultPresentSound': defaultPresentSound,
'defaultPresentBadge': defaultPresentBadge,
'notificationCategories': notificationCategories
.map((e) => e.toMap()) // ignore: always_specify_types
.toList(),
};
}
extension on DarwinNotificationAttachmentThumbnailClippingRect {
Map<String, Object> toMap() => <String, Object>{
'x': x,
'y': y,
'width': width,
'height': height,
};
}
extension DarwinNotificationAttachmentMapper on DarwinNotificationAttachment {
Map<String, Object?> toMap() => <String, Object?>{
'identifier': identifier ?? '',
'filePath': filePath,
'hideThumbnail': hideThumbnail,
'thumbnailClippingRect': thumbnailClippingRect?.toMap(),
};
}
extension DarwinNotificationDetailsMapper on DarwinNotificationDetails {
Map<String, Object?> toMap() => <String, Object?>{
'presentAlert': presentAlert,
'presentSound': presentSound,
'presentBadge': presentBadge,
'subtitle': subtitle,
'sound': sound,
'badgeNumber': badgeNumber,
'threadIdentifier': threadIdentifier,
'interruptionLevel': interruptionLevel?.value,
'attachments': attachments
?.map((a) => a.toMap()) // ignore: always_specify_types
.toList(),
'categoryIdentifier': categoryIdentifier,
};
}