From f9274e070e6d0d3ad9b6a5a333cf4970a34a33fe Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Sun, 27 Sep 2026 16:16:41 +0300 Subject: [PATCH] improvements --- .../firebase_notification_manger.dart | 22 ++++++++++- lib/main.dart | 1 - lib/new_views/pages/splash_page.dart | 37 ++++++++++--------- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/lib/controllers/notification/firebase_notification_manger.dart b/lib/controllers/notification/firebase_notification_manger.dart index 7b52aeaf..69b062be 100644 --- a/lib/controllers/notification/firebase_notification_manger.dart +++ b/lib/controllers/notification/firebase_notification_manger.dart @@ -35,10 +35,28 @@ Future firebaseMessagingBackgroundHandler(RemoteMessage message) async { } @pragma('vm:entry-point') -Future onBackgroundMessage(CallEvent event) async { +Future onBackgroundMessage(CallEvent event1) async { // This executes when a background/killed action happens - switch (event.eventName) { + + FlutterCallkitIncoming.onEvent.listen((CallEvent? event) { + switch (event!.eventName) { + case CallEventConstants.actionCallAccept: + // Handle logic when user hits Accept while app transitions to foreground + // var extraData = event?.body['extra']; + // Navigate to Call Screen + print("onBackgroundMessage:actionCallAccept:${event}"); + break; + case CallEventConstants.actionCallDecline: + // Notify backend that user declined + print("onBackgroundMessage:actionCallDecline:${event}"); + break; + default: + break; + } + }); + + switch (event1.eventName) { case CallEventConstants.actionCallAccept: "actionCallAccept".showToast; break; diff --git a/lib/main.dart b/lib/main.dart index 3c151786..797e49ef 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -161,7 +161,6 @@ void main() async { if (Platform.isAndroid) { FlutterCallkitIncoming.onBackgroundMessage(onBackgroundMessage); } - FlutterCallkitIncoming.endAllCalls(); SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge); // HttpOverrides.global = MyHttpOverrides(); // for later use. _configureLocalTimeZone(); diff --git a/lib/new_views/pages/splash_page.dart b/lib/new_views/pages/splash_page.dart index 6fea3c6f..102ea61e 100644 --- a/lib/new_views/pages/splash_page.dart +++ b/lib/new_views/pages/splash_page.dart @@ -6,6 +6,7 @@ import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flare_flutter/flare_actor.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_callkit_incoming/entities/call_kit_params.dart'; import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart'; import 'package:local_auth/local_auth.dart'; import 'package:provider/provider.dart'; @@ -16,6 +17,8 @@ import 'package:test_sa/controllers/notification/firebase_notification_manger.da import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; import 'package:test_sa/extensions/widget_extensions.dart'; +import 'package:test_sa/modules/cx_module/chat/calling/audio_call_page.dart'; +import 'package:test_sa/modules/cx_module/chat/model/chat_participant_model.dart'; import 'package:test_sa/new_views/app_style/app_color.dart'; import 'package:test_sa/new_views/common_widgets/app_lazy_loading.dart'; import 'package:test_sa/new_views/pages/land_page/land_page.dart'; @@ -238,27 +241,27 @@ class _SplashPageState extends State { ); } - checkVoipCalling() async { + Future checkVoipCalling() async { var activeCalls = await FlutterCallkitIncoming.activeCalls(); if (activeCalls is List && activeCalls.isNotEmpty) { - final lastCall = activeCalls.last; + CallKitParams lastCall = activeCalls.last; + if (lastCall.isAccepted) { + final String? callerId = lastCall.extra?['callerId']; + final String? callUuid = lastCall.id; - print("lastCall:$lastCall"); - - // // Check if the last state recorded was an accepted call - // if (lastCall['isAccepted'] == true) { - // final String? callerId = lastCall['extra']['callerId']; - // final String? callUuid = lastCall['id']; - // - // await FlutterCallkitIncoming.setCallConnected(callUuid!); - // - // // Route user to the calling interface - // Navigator.push( - // context, - // MaterialPageRoute(builder: (context) => InAppCallScreen(callerId: callerId)), - // ); - // } + await FlutterCallkitIncoming.setCallConnected(callUuid!); + await Navigator.of(context).push(MaterialPageRoute( + builder: (_) => AudioCallPage( + sender: Participants(employeeNumber: lastCall.extra?["calleeEmployeeNumber"]), + recipient: Participants(employeeNumber: lastCall.extra?["callerEmployeeNumber"]), + moduleId: int.parse(lastCall.extra!["moduleId"]), + isAccept: true))); + FlutterCallkitIncoming.endCall(lastCall.extra?["callId"]); + FlutterCallkitIncoming.endAllCalls(); + } + } else { + await FlutterCallkitIncoming.endAllCalls(); } }