|
|
|
|
@ -10,16 +10,17 @@ import 'package:diplomaticquarterapp/pages/DrawerPages/notifications/notificatio
|
|
|
|
|
import 'package:diplomaticquarterapp/pages/landing/landing_page.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/pages/livecare/incoming_call.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/pages/webRTC/OpenTok/OpenTok.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/LocalNotification.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/app-permissions.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
|
|
|
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
|
|
|
import 'package:firebase_messaging/firebase_messaging.dart' as fir;
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
// import 'package:flutter_hms_gms_availability/flutter_hms_gms_availability.dart';
|
|
|
|
|
import 'package:flutter_ios_voip_kit/call_state_type.dart';
|
|
|
|
|
import 'package:flutter_ios_voip_kit/flutter_ios_voip_kit.dart';
|
|
|
|
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|
|
|
|
import 'package:huawei_hmsavailability/huawei_hmsavailability.dart';
|
|
|
|
|
import 'package:huawei_push/huawei_push.dart' as h_push;
|
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
|
@ -253,7 +254,7 @@ class PushNotificationHandler {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
FirebaseMessaging.instance.getInitialMessage().then((RemoteMessage message) async {
|
|
|
|
|
if(message != null) {
|
|
|
|
|
if (message != null) {
|
|
|
|
|
// print("Firebase getInitialMessage with message : ${message.data.toString()}");
|
|
|
|
|
subscribeFCMTopic();
|
|
|
|
|
if (Platform.isIOS)
|
|
|
|
|
@ -263,9 +264,7 @@ class PushNotificationHandler {
|
|
|
|
|
else if (message != null) newMessage(message);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch(ex) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
|
|
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
|
|
|
|
|
print("Firebase onMessage!!!");
|
|
|
|
|
@ -371,109 +370,28 @@ class PushNotificationHandler {
|
|
|
|
|
_incomingCall(call_data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* todo verify all functionality */
|
|
|
|
|
// _firebaseMessaging.configure(
|
|
|
|
|
// // onMessage: (Map<String, dynamic> message) async {
|
|
|
|
|
// // // showDialog("onMessage: $message");
|
|
|
|
|
// // print("onMessage: $message");
|
|
|
|
|
// // print(message);
|
|
|
|
|
// // print(message['name']);
|
|
|
|
|
// // print(message['appointmentdate']);
|
|
|
|
|
// //
|
|
|
|
|
// // if (Platform.isIOS) {
|
|
|
|
|
// // if (message['is_call'] == "true") {
|
|
|
|
|
// // var route = ModalRoute.of(context);
|
|
|
|
|
// //
|
|
|
|
|
// // if (route != null) {
|
|
|
|
|
// // print(route.settings.name);
|
|
|
|
|
// // }
|
|
|
|
|
// //s
|
|
|
|
|
// // Map<String, dynamic> myMap = new Map<String, dynamic>.from(mesage);
|
|
|
|
|
// // print(myMap);
|
|
|
|
|
// // LandingPage.isOpenCallPage = true;
|
|
|
|
|
// // LandingPage.incomingCallData = IncomingCallData.fromJson(myMap);
|
|
|
|
|
// // if (!isPageNavigated) {
|
|
|
|
|
// // isPageNavigated = true;
|
|
|
|
|
// // Navigator.push(context, MaterialPageRoute(builder: (context) => IncomingCall(incomingCallData: LandingPage.incomingCallData))).then((value) {
|
|
|
|
|
// // isPageNavigated = false;
|
|
|
|
|
// // });
|
|
|
|
|
// // }
|
|
|
|
|
// // } else {
|
|
|
|
|
// // print("Is Call Not Found iOS");
|
|
|
|
|
// // }
|
|
|
|
|
// // } else {
|
|
|
|
|
// // print("Is Call Not Found iOS");
|
|
|
|
|
// // }
|
|
|
|
|
// //
|
|
|
|
|
// // if (Platform.isAndroid) {
|
|
|
|
|
// // if (message['data'].containsKey("is_call")) {
|
|
|
|
|
// // var route = ModalRoute.of(context);
|
|
|
|
|
// //
|
|
|
|
|
// // if (route != null) {
|
|
|
|
|
// // print(route.settings.name);
|
|
|
|
|
// // }
|
|
|
|
|
// //
|
|
|
|
|
// // Map<String, dynamic> myMap = new Map<String, dynamic>.from(message['data']);
|
|
|
|
|
// // print(myMap);
|
|
|
|
|
// // if (LandingPage.isOpenCallPage) {
|
|
|
|
|
// // return;
|
|
|
|
|
// // }
|
|
|
|
|
// // LandingPage.isOpenCallPage = true;
|
|
|
|
|
// // LandingPage.incomingCallData = IncomingCallData.fromJson(myMap);
|
|
|
|
|
// // if (!isPageNavigated) {
|
|
|
|
|
// // isPageNavigated = true;
|
|
|
|
|
// // Navigator.push(context, MaterialPageRoute(builder: (context) => IncomingCall(incomingCallData: LandingPage.incomingCallData))).then((value) {
|
|
|
|
|
// // Future.delayed(Duration(seconds: 5), () {
|
|
|
|
|
// // isPageNavigated = false;
|
|
|
|
|
// // });
|
|
|
|
|
// // });
|
|
|
|
|
// // }
|
|
|
|
|
// // } else {
|
|
|
|
|
// // print("Is Call Not Found Android");
|
|
|
|
|
// // LocalNotification.getInstance().showNow(title: message['notification']['title'], subtitle: message['notification']['body']);
|
|
|
|
|
// // }
|
|
|
|
|
// // } else {
|
|
|
|
|
// // print("Is Call Not Found Android");
|
|
|
|
|
// // }
|
|
|
|
|
// // },
|
|
|
|
|
// onBackgroundMessage: Platform.isIOS ? null : myBackgroundMessageHandler,
|
|
|
|
|
// onLaunch: (Map<String, dynamic> message) async {
|
|
|
|
|
// print("onLaunch: $message");
|
|
|
|
|
// // showDialog("onLaunch: $message");
|
|
|
|
|
// },
|
|
|
|
|
// onResume: (Map<String, dynamic> message) async {
|
|
|
|
|
// print("onResume: $message");
|
|
|
|
|
// print(message);
|
|
|
|
|
// print(message['name']);
|
|
|
|
|
// print(message['appointmentdate']);
|
|
|
|
|
//
|
|
|
|
|
// // showDialog("onResume: $message");
|
|
|
|
|
//
|
|
|
|
|
// if (Platform.isIOS) {
|
|
|
|
|
// if (message['is_call'] == "true") {
|
|
|
|
|
// var route = ModalRoute.of(context);
|
|
|
|
|
//
|
|
|
|
|
// if (route != null) {
|
|
|
|
|
// print(route.settings.name);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// Map<String, dynamic> myMap = new Map<String, dynamic>.from(message);
|
|
|
|
|
// print(myMap);
|
|
|
|
|
// LandingPage.isOpenCallPage = true;
|
|
|
|
|
// LandingPage.incomingCallData = IncomingCallData.fromJson(myMap);
|
|
|
|
|
// if (!isPageNavigated) {
|
|
|
|
|
// isPageNavigated = true;
|
|
|
|
|
// Navigator.push(context, MaterialPageRoute(builder: (context) => IncomingCall(incomingCallData: LandingPage.incomingCallData))).then((value) {
|
|
|
|
|
// isPageNavigated = false;
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// print("Is Call Not Found iOS");
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// print("Is Call Not Found iOS");
|
|
|
|
|
// }
|
|
|
|
|
// },
|
|
|
|
|
// );
|
|
|
|
|
Future<void> isAndroidPermissionGranted() async {
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
final bool granted = await flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()?.areNotificationsEnabled() ?? false;
|
|
|
|
|
if (granted) {
|
|
|
|
|
print("-------------------- Permission Granted ------------------------");
|
|
|
|
|
print(granted);
|
|
|
|
|
} else {
|
|
|
|
|
await requestPermissions();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> requestPermissions() async {
|
|
|
|
|
try {
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
await flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<IOSFlutterLocalNotificationsPlugin>()?.requestPermissions(alert: true, badge: true, sound: true);
|
|
|
|
|
} else if (Platform.isAndroid) {
|
|
|
|
|
Permission.notification.request();
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
debugPrint(err);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|