This commit is contained in:
Hamza-Ayed
2023-08-15 23:55:41 +03:00
parent 65ade9c874
commit 9b3716aabd
19 changed files with 466 additions and 189 deletions

View File

@@ -1,8 +1,10 @@
import 'dart:convert';
import 'dart:io';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import 'package:ride/constant/colors.dart';
import '../../constant/box_name.dart';
import '../../constant/credential.dart';
@@ -29,17 +31,39 @@ class FirebasMessagesController extends GetxController {
await FirebaseMessaging.instance.getNotificationSettings();
print('------noti======');
print(notificationSettings!.authorizationStatus.toString());
// if (notificationSettings?.authorizationStatus.toString() ==
// 'AuthorizationStatus.denied') {
// await Get.defaultDialog(
// title: 'AuthorizationStatus',
// content: TextButton(
// onPressed: () {
// requestPermission();
// },
// child: Text(
// "Text Button",
// ),
// ),
// );
// }
update();
}
void requestPermission() async {
Future checkAndRequestPermission() async {
if (notificationSettings!.authorizationStatus ==
AuthorizationStatus.denied) {
await requestPermission();
}
}
Future requestPermission() async {
// Check if the platform is Android
if (Platform.isAndroid) {
// Request permission for Android
fcmToken.requestPermission().then((value) {
if (value!.authorizationStatus == AuthorizationStatus.denied) {
if (value.authorizationStatus == AuthorizationStatus.denied) {
print('dddddddddddddddddddddd');
}
print(value.authorizationStatus);
});
} else {
// Request permission for iOS
@@ -86,8 +110,8 @@ class FirebasMessagesController extends GetxController {
// final SharedPreferences prefs = await SharedPreferences.getInstance();
await fcmToken.getToken().then(
(token) {
// print(token);/
box.write(BoxName.tokenFCM, token);
print(box.read(BoxName.tokenFCM).toString());
},
);
FirebaseMessaging.onMessage.listen((event) {
@@ -95,8 +119,8 @@ class FirebasMessagesController extends GetxController {
'onMessage: ${event.notification!.title} ${event.notification!.body}');
if (Get.currentRoute == '/') {
// If the app is in the foreground, show a dialog to the user
if (event.notification!.title.toString().contains('reef')) {
// Get.snackbar('reeffff', 'message');
if (event.notification!.title.toString().contains('ride')) {
Get.snackbar('ride', 'message', backgroundColor: AppColor.redColor);
} else if (event.notification!.title.toString().contains('انذار')) {
// Get.to(() => const ProfilePage());
} else if (event.notification!.title
@@ -112,8 +136,8 @@ class FirebasMessagesController extends GetxController {
if (notification != null && android != null) {
print(
'onMessageOpenedApp: ${notification.title} ${notification.body}');
if (event.notification!.title.toString().contains('reef')) {
// Get.snackbar('reef', '');
if (event.notification!.title.toString().contains('ride')) {
Get.snackbar('ride', 'message', backgroundColor: AppColor.redColor);
// SendGpsNow().getSiteNotification();
} else if (event.notification!.title.toString().contains('انذار')) {
// Get.to(() => const ProfilePage());
@@ -134,8 +158,8 @@ class FirebasMessagesController extends GetxController {
if (notification != null) {
print('onMessageOpenedApp: ${notification.title} ${notification.body}');
if (event.notification!.title.toString().contains('reef')) {
// Get.snackbar('reef', '');
if (event.notification!.title.toString().contains('ride')) {
Get.snackbar('ride', 'message', backgroundColor: AppColor.redColor);
// SendGpsNow().getSiteNotification();
} else if (event.notification!.title.toString().contains('انذار')) {
// Get.to(() => const ProfilePage());