notification handler
parent
48dfddada9
commit
a37be56e47
@ -0,0 +1,26 @@
|
||||
class PatientQueue {
|
||||
|
||||
final String? title; // for title of the notification
|
||||
final String? contentText; // for the content of the notification
|
||||
final String? nextTicket;
|
||||
final String? currentlyServingStatus;
|
||||
final String? currentlyServing;
|
||||
final String? nextTicketStatus;
|
||||
final int? nextTicketBackground;// background will be same as of the [Utils.getCardButtonColor]
|
||||
|
||||
const PatientQueue({this.title, this.contentText, this.nextTicket, this.currentlyServingStatus, this.currentlyServing, this.nextTicketStatus, this.nextTicketBackground});
|
||||
|
||||
/// Converts this PatientQueue object to a map.
|
||||
/// This is used for passing data to the native side for Live Activities.
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'title': title,
|
||||
'contentText': contentText,
|
||||
'nextTicket': nextTicket,
|
||||
'currentlyServingStatus': currentlyServingStatus,
|
||||
'currentlyServing': currentlyServing,
|
||||
'nextTicketStatus': nextTicketStatus,
|
||||
'nextTicketBackground': nextTicketBackground,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
|
||||
|
||||
// Background message handler (must be top-level function)
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
||||
await Firebase.initializeApp();
|
||||
print('Handling background message: ${message.messageId}');
|
||||
}
|
||||
|
||||
class NotificationService {
|
||||
final FirebaseMessaging _fcm = FirebaseMessaging.instance;
|
||||
|
||||
|
||||
Future<void> initialize() async {
|
||||
|
||||
String? token = await _fcm. getToken();
|
||||
print('FCM Token: $token');
|
||||
|
||||
// Set up background handler
|
||||
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
|
||||
|
||||
// Foreground message handler
|
||||
FirebaseMessaging.onMessage.listen(_handleForegroundMessage);
|
||||
|
||||
}
|
||||
|
||||
// Foreground message handler
|
||||
void _handleForegroundMessage(RemoteMessage message) {
|
||||
print('Foreground notification: ${message.notification?.title}');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue