|
| 1 | +import 'package:equatable/equatable.dart'; |
| 2 | +import 'package:json_annotation/json_annotation.dart'; |
| 3 | + |
| 4 | +part 'firebase_request_body.g.dart'; |
| 5 | + |
| 6 | +/// {@template firebase_request_body} |
| 7 | +/// Represents the top-level structure for a Firebase Cloud Messaging |
| 8 | +/// v1 API request. |
| 9 | +/// {@endtemplate} |
| 10 | +@JsonSerializable(explicitToJson: true, includeIfNull: true, checked: true) |
| 11 | +class FirebaseRequestBody extends Equatable { |
| 12 | + /// {@macro firebase_request_body} |
| 13 | + const FirebaseRequestBody({required this.message}); |
| 14 | + |
| 15 | + /// The message payload. |
| 16 | + final FirebaseMessage message; |
| 17 | + |
| 18 | + /// Converts this [FirebaseRequestBody] instance to a JSON map. |
| 19 | + Map<String, dynamic> toJson() => _$FirebaseRequestBodyToJson(this); |
| 20 | + |
| 21 | + @override |
| 22 | + List<Object> get props => [message]; |
| 23 | +} |
| 24 | + |
| 25 | +/// {@template firebase_message} |
| 26 | +/// Represents the message object within a Firebase request. |
| 27 | +/// {@endtemplate} |
| 28 | +@JsonSerializable(explicitToJson: true, includeIfNull: true, checked: true) |
| 29 | +class FirebaseMessage extends Equatable { |
| 30 | + /// {@macro firebase_message} |
| 31 | + const FirebaseMessage({ |
| 32 | + required this.token, |
| 33 | + required this.notification, |
| 34 | + required this.data, |
| 35 | + }); |
| 36 | + |
| 37 | + /// The registration token of the device to send the message to. |
| 38 | + final String token; |
| 39 | + |
| 40 | + /// The notification content. |
| 41 | + final FirebaseNotification notification; |
| 42 | + |
| 43 | + /// The custom data payload. |
| 44 | + final Map<String, dynamic> data; |
| 45 | + |
| 46 | + /// Converts this [FirebaseMessage] instance to a JSON map. |
| 47 | + Map<String, dynamic> toJson() => _$FirebaseMessageToJson(this); |
| 48 | + |
| 49 | + @override |
| 50 | + List<Object> get props => [token, notification, data]; |
| 51 | +} |
| 52 | + |
| 53 | +/// {@template firebase_notification} |
| 54 | +/// Represents the notification content within a Firebase message. |
| 55 | +/// {@endtemplate} |
| 56 | +@JsonSerializable(explicitToJson: true, includeIfNull: true, checked: true) |
| 57 | +class FirebaseNotification extends Equatable { |
| 58 | + /// {@macro firebase_notification} |
| 59 | + const FirebaseNotification({ |
| 60 | + required this.title, |
| 61 | + required this.body, |
| 62 | + this.image, |
| 63 | + }); |
| 64 | + |
| 65 | + /// The notification's title. |
| 66 | + final String title; |
| 67 | + |
| 68 | + /// The notification's body text. |
| 69 | + final String body; |
| 70 | + |
| 71 | + /// The URL of an image to be displayed in the notification. |
| 72 | + final String? image; |
| 73 | + |
| 74 | + /// Converts this [FirebaseNotification] instance to a JSON map. |
| 75 | + Map<String, dynamic> toJson() => _$FirebaseNotificationToJson(this); |
| 76 | + |
| 77 | + @override |
| 78 | + List<Object?> get props => [title, body, image]; |
| 79 | +} |
0 commit comments