@@ -2,9 +2,9 @@ import 'dart:convert';
2
2
3
3
/// Push Notification object from https://spec.matrix.org/v1.2/push-gateway-api/
4
4
class PushNotification {
5
- final Map <String , dynamic >? content;
5
+ final Map <String , Object ? >? content;
6
6
final PushNotificationCounts ? counts;
7
- final List <PushNotificationDevice > devices;
7
+ final List <PushNotificationDevice >? devices;
8
8
final String ? eventId;
9
9
final String ? prio;
10
10
final String ? roomAlias;
@@ -17,7 +17,7 @@ class PushNotification {
17
17
const PushNotification ({
18
18
this .content,
19
19
this .counts,
20
- required this .devices,
20
+ this .devices,
21
21
this .eventId,
22
22
this .prio,
23
23
this .roomAlias,
@@ -30,39 +30,44 @@ class PushNotification {
30
30
31
31
/// Generate a Push Notification object from JSON. It also supports a
32
32
/// `map<String, String>` which usually comes from Firebase Cloud Messaging.
33
- factory PushNotification .fromJson (Map <String , dynamic > json) =>
33
+ factory PushNotification .fromJson (Map <String , Object ? > json) =>
34
34
PushNotification (
35
35
content: json['content' ] is Map
36
- ? Map <String , dynamic >.from (json['content' ])
36
+ ? Map <String , Object ? >.from (json['content' ] as Map )
37
37
: json['content' ] is String
38
- ? jsonDecode (json['content' ])
38
+ ? jsonDecode (json['content' ] as String )
39
39
: null ,
40
40
counts: json['counts' ] is Map
41
- ? PushNotificationCounts .fromJson (json['counts' ])
41
+ ? PushNotificationCounts .fromJson (
42
+ json['counts' ] as Map <String , Object ?>,
43
+ )
42
44
: json['counts' ] is String
43
- ? PushNotificationCounts .fromJson (jsonDecode (json['counts' ]))
45
+ ? PushNotificationCounts .fromJson (
46
+ jsonDecode (json['counts' ] as String ),
47
+ )
44
48
: null ,
45
49
devices: json['devices' ] is List
46
50
? (json['devices' ] as List )
47
51
.map ((d) => PushNotificationDevice .fromJson (d))
48
52
.toList ()
49
- : (jsonDecode (json['devices' ]) as List )
53
+ : (jsonDecode (json['devices' ] as String ) as List )
50
54
.map ((d) => PushNotificationDevice .fromJson (d))
51
55
.toList (),
52
- eventId: json['event_id' ],
53
- prio: json['prio' ],
54
- roomAlias: json['room_alias' ],
55
- roomId: json['room_id' ],
56
- roomName: json['room_name' ],
57
- sender: json['sender' ],
58
- senderDisplayName: json['sender_display_name' ],
59
- type: json['type' ],
56
+ eventId: json['event_id' ] as String ? ,
57
+ prio: json['prio' ] as String ? ,
58
+ roomAlias: json['room_alias' ] as String ? ,
59
+ roomId: json['room_id' ] as String ? ,
60
+ roomName: json['room_name' ] as String ? ,
61
+ sender: json['sender' ] as String ? ,
62
+ senderDisplayName: json['sender_display_name' ] as String ? ,
63
+ type: json['type' ] as String ? ,
60
64
);
61
65
62
- Map <String , dynamic > toJson () => {
66
+ Map <String , Object ? > toJson () => {
63
67
if (content != null ) 'content' : content,
64
68
if (counts != null ) 'counts' : counts? .toJson (),
65
- 'devices' : devices.map ((i) => i.toJson ()).toList (),
69
+ if (devices != null )
70
+ 'devices' : devices? .map ((i) => i.toJson ()).toList (),
66
71
if (eventId != null ) 'event_id' : eventId,
67
72
if (prio != null ) 'prio' : prio,
68
73
if (roomAlias != null ) 'room_alias' : roomAlias,
@@ -83,45 +88,47 @@ class PushNotificationCounts {
83
88
this .unread,
84
89
});
85
90
86
- factory PushNotificationCounts .fromJson (Map <String , dynamic > json) =>
91
+ factory PushNotificationCounts .fromJson (Map <String , Object ? > json) =>
87
92
PushNotificationCounts (
88
- missedCalls: json['missed_calls' ],
89
- unread: json['unread' ],
93
+ missedCalls: json['missed_calls' ] as int ? ,
94
+ unread: json['unread' ] as int ? ,
90
95
);
91
96
92
- Map <String , dynamic > toJson () => {
97
+ Map <String , Object ? > toJson () => {
93
98
if (missedCalls != null ) 'missed_calls' : missedCalls,
94
99
if (unread != null ) 'unread' : unread,
95
100
};
96
101
}
97
102
98
103
class PushNotificationDevice {
99
- final String appId;
100
- final Map <String , dynamic >? data;
101
- final String pushkey;
104
+ final String ? appId;
105
+ final Map <String , Object ? >? data;
106
+ final String ? pushkey;
102
107
final int ? pushkeyTs;
103
108
final Tweaks ? tweaks;
104
109
105
110
const PushNotificationDevice ({
106
- required this .appId,
111
+ this .appId,
107
112
this .data,
108
- required this .pushkey,
113
+ this .pushkey,
109
114
this .pushkeyTs,
110
115
this .tweaks,
111
116
});
112
117
113
- factory PushNotificationDevice .fromJson (Map <String , dynamic > json) =>
118
+ factory PushNotificationDevice .fromJson (Map <String , Object ? > json) =>
114
119
PushNotificationDevice (
115
- appId: json['app_id' ],
120
+ appId: json['app_id' ] as String ? ,
116
121
data: json['data' ] == null
117
122
? null
118
- : Map <String , dynamic >.from (json['data' ]),
119
- pushkey: json['pushkey' ],
120
- pushkeyTs: json['pushkey_ts' ],
121
- tweaks: json['tweaks' ] == null ? null : Tweaks .fromJson (json['tweaks' ]),
123
+ : Map <String , Object ?>.from (json['data' ] as Map ),
124
+ pushkey: json['pushkey' ] as String ? ,
125
+ pushkeyTs: json['pushkey_ts' ] as int ? ,
126
+ tweaks: json['tweaks' ] == null
127
+ ? null
128
+ : Tweaks .fromJson (json['tweaks' ] as Map <String , Object ?>),
122
129
);
123
130
124
- Map <String , dynamic > toJson () => {
131
+ Map <String , Object ? > toJson () => {
125
132
'app_id' : appId,
126
133
if (data != null ) 'data' : data,
127
134
'pushkey' : pushkey,
@@ -137,11 +144,11 @@ class Tweaks {
137
144
this .sound,
138
145
});
139
146
140
- factory Tweaks .fromJson (Map <String , dynamic > json) => Tweaks (
141
- sound: json['sound' ],
147
+ factory Tweaks .fromJson (Map <String , Object ? > json) => Tweaks (
148
+ sound: json['sound' ] as String ? ,
142
149
);
143
150
144
- Map <String , dynamic > toJson () => {
151
+ Map <String , Object ? > toJson () => {
145
152
if (sound != null ) 'sound' : sound,
146
153
};
147
154
}
0 commit comments