notification handler

live_activities
tahaalam 4 weeks ago
parent 48dfddada9
commit a37be56e47

@ -36,7 +36,7 @@ class CustomLiveActivityManager(context: Context) :
)
private suspend fun updateRemoteViews(data: Map<String, Any>) {
val (background, textColor, containerBackground) = when (data["nextStepBackground"] as? Int) {
val (background, textColor, containerBackground) = when (data["nextTicketBackground"] as? Int) {
0 -> Triple(R. drawable.grey_rounded_corner_widget, R.color.text_color, R.drawable.whitebg_yellow_border_rounded_corner_widget)
1 -> Triple(R.drawable.dark_red_rounded_corner_widget, R.color.colorWhite, R.drawable.whitebg_red_border_rounded_corner_widget)
2 -> Triple(R.drawable.green_rounded_corner_widget, R. color.colorWhite, R. drawable.whitebg_green_border_rounded_corner_widget)
@ -46,10 +46,10 @@ class CustomLiveActivityManager(context: Context) :
remoteViews.setInt(R.id.nextStep, "setBackgroundResource", background)
remoteViews.setInt(R.id.container, "setBackgroundResource", containerBackground)
remoteViews.setTextColor(R.id.nextStep, ContextCompat.getColor(context, textColor))
remoteViews.setTextViewText(R.id.countvalue, data["currentTicket"] as? String ?: "")
remoteViews.setTextViewText(R.id.status, data["status"] as? String ?: "")
remoteViews.setTextViewText(R.id.countvalue, data["nextTicket"] as? String ?: "")
remoteViews.setTextViewText(R.id.status, data["currentlyServingStatus"] as? String ?: "")
remoteViews.setTextViewText(R. id.currentlyserving, data["currentlyServing"] as? String ?: "")
remoteViews.setTextViewText(R.id.nextStep, data["nextStep"] as? String ?: "")
remoteViews.setTextViewText(R.id.nextStep, data["nextTicketStatus"] as? String ?: "")
}
private suspend fun updateCollapsedView(data: Map<String, Any>) {
@ -70,6 +70,11 @@ class CustomLiveActivityManager(context: Context) :
event: String,
data: Map<String, Any>
): Notification {
val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (notificationManager != null) {
notificationManager.cancelAll();
}
collapesView.apply {
updateCollapsedView(data)
}

@ -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}');
}
}

@ -43,7 +43,8 @@ class CalenderUtilsNew {
description: description,
startDate: scheduleDateTime!,
endDate: scheduleDateTime!.add(Duration(minutes: 30)),
reminderMinutes: reminderMinutes);
// reminderMinutes: reminderMinutes
);
return eventResult.isNotEmpty;
// }

@ -19,9 +19,11 @@ import 'package:flutter_ios_voip_kit_karmm/flutter_ios_voip_kit.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:get_it/get_it.dart';
import 'package:hmg_patient_app_new/core/common_models/patient_queue.dart';
import 'package:hmg_patient_app_new/core/utils/local_notifications.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/services/cache_service.dart';
import 'package:live_activities/live_activities.dart' show LiveActivities;
import 'package:permission_handler/permission_handler.dart';
import 'package:uuid/uuid.dart';
@ -33,12 +35,36 @@ Future<dynamic> backgroundMessageHandler(dynamic message) async {
print("Firebase backgroundMessageHandler!!!");
await Firebase.initializeApp();
fir.RemoteMessage message_;
if(message.data == null ){
return;
}
if (message.data != null && (message.data['is_call'] == 'true' || message.data['is_call'] == true)) {
if (message.data['is_call'] == 'true' || message.data['is_call'] == true) {
// showCallkitIncoming(message);
_incomingCall(message.data);
return;
} else {}
}
if(message.data['isLiveActivity'] == true){
await LiveActivities().endAllActivities();
await Permission.notification.request();
PatientQueue _patientQueue =
PatientQueue(
title: message.data['title']??"HMG",
contentText: message.data['contentText']??"HMG Queue line",
nextTicket: message.data['nextTicket']??"IME-1",
currentlyServingStatus: message.data['currentlyServingStatus']??"Call for vital signs",
currentlyServing: message.data['currentlyServing']??"IME-3",
nextTicketStatus: message.data['nextTicketStatus']??"Please wait! you will be called for vital signs",
nextTicketBackground: message.data['nextTicketBackground']??2
);
await LiveActivities().createActivity(
DateTime.now().millisecondsSinceEpoch.toString(),
_patientQueue.toMap(),
);
}
}
callPage(String sessionID, String token) async {}

@ -3,6 +3,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/common_models/patient_queue.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
@ -24,32 +25,7 @@ import 'package:provider/provider.dart';
import '../../../core/utils/utils.dart';
import '../../../theme/colors.dart';
import '../../radiology/radiology_orders_page.dart' show RadiologyOrdersPage;
class PatientQueue {
final String? title; // for title of the notification
final String? contentText; // for the content of the notification
final String? currentTicket;
final String? status;
final String? currentlyServing;
final String? nextStep;
final int? nextStepBackground;// background will be same as of the [Utils.getCardButtonColor]
const PatientQueue({this.title, this.contentText, this.currentTicket, this.status, this.currentlyServing, this.nextStep, this.nextStepBackground});
/// 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,
'currentTicket': currentTicket,
'status': status,
'currentlyServing': currentlyServing,
'nextStep': nextStep,
'nextStepBackground': nextStepBackground,
};
}
}
class SmallServiceCard extends StatefulWidget {
final String serviceName;
@ -194,13 +170,13 @@ class _SmallServiceCardState extends State<SmallServiceCard> {
await Permission.notification.request();
_patientQueue =
PatientQueue(
title: "HMG",
title: "HMG",
contentText: "HMG Queue line",
currentTicket: "IME-1",
status: "Call for vital signs",
nextTicket: "IME-1",
currentlyServingStatus: "Call for vital signs",
currentlyServing: "IME-3",
nextStep: "Please wait! you will be called for vital signs",
nextStepBackground: 2
nextTicketStatus: "Please wait! you will be called for vital signs",
nextTicketBackground: 2
);
final activityId =

Loading…
Cancel
Save