44 lines
1.1 KiB
Dart
44 lines
1.1 KiB
Dart
|
|
sealed class NotificationPayload {
|
||
|
|
const NotificationPayload();
|
||
|
|
}
|
||
|
|
|
||
|
|
final class NotificationPayloadNone extends NotificationPayload {
|
||
|
|
const NotificationPayloadNone();
|
||
|
|
}
|
||
|
|
|
||
|
|
final class NotificationPayloadRoute extends NotificationPayload {
|
||
|
|
const NotificationPayloadRoute({
|
||
|
|
required this.route,
|
||
|
|
this.entityId,
|
||
|
|
this.tab,
|
||
|
|
});
|
||
|
|
|
||
|
|
final String route;
|
||
|
|
final String? entityId;
|
||
|
|
final String? tab;
|
||
|
|
}
|
||
|
|
|
||
|
|
final class NotificationPayloadUrl extends NotificationPayload {
|
||
|
|
const NotificationPayloadUrl({required this.url});
|
||
|
|
|
||
|
|
final String url;
|
||
|
|
}
|
||
|
|
|
||
|
|
NotificationPayload parseNotificationPayload(Map<String, dynamic> json) {
|
||
|
|
final action = json['action'];
|
||
|
|
switch (action) {
|
||
|
|
case 'open_route':
|
||
|
|
return NotificationPayloadRoute(
|
||
|
|
route: json['route'] as String? ?? '',
|
||
|
|
entityId: json['entityId'] as String?,
|
||
|
|
tab: json['tab'] as String?,
|
||
|
|
);
|
||
|
|
case 'open_url':
|
||
|
|
return NotificationPayloadUrl(url: json['url'] as String? ?? '');
|
||
|
|
case 'none':
|
||
|
|
return const NotificationPayloadNone();
|
||
|
|
default:
|
||
|
|
return const NotificationPayloadNone();
|
||
|
|
}
|
||
|
|
}
|