8/27/1
This commit is contained in:
@@ -136,6 +136,8 @@ class FirebaseMessagesController extends GetxController {
|
||||
// 'Cancel Trip'.tr, 'Passenger Cancel Trip'.tr, 'cancel', '');
|
||||
// }
|
||||
cancelTripDialog();
|
||||
} else if (message.notification!.title == 'Cancel') {
|
||||
cancelTripDialog1();
|
||||
} else if (message.notification!.title! == 'token change') {
|
||||
// NotificationController()
|
||||
// .showNotification('token change'.tr, 'token change', 'cancel');
|
||||
@@ -316,6 +318,21 @@ class FirebaseMessagesController extends GetxController {
|
||||
}));
|
||||
}
|
||||
|
||||
Future<dynamic> cancelTripDialog1() {
|
||||
return Get.defaultDialog(
|
||||
barrierDismissible: false,
|
||||
title: 'Passenger Cancel Trip'.tr,
|
||||
middleText:
|
||||
'Trip Cancelled. The cost of the trip will be added to your wallet.'
|
||||
.tr,
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Ok'.tr,
|
||||
onPressed: () {
|
||||
box.write(BoxName.rideStatus, 'Cancel');
|
||||
Get.offAll(HomeCaptain());
|
||||
}));
|
||||
}
|
||||
|
||||
// Future<dynamic> driverArrivePassengerDialoge() {
|
||||
// return Get.defaultDialog(
|
||||
// barrierDismissible: false,
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:SEFER/constant/box_name.dart';
|
||||
import 'package:SEFER/constant/colors.dart';
|
||||
import 'package:SEFER/views/home/Captin/orderCaptin/order_request_page.dart';
|
||||
import 'package:SEFER/views/home/my_wallet/walet_captain.dart';
|
||||
import 'package:SEFER/views/home/Captin/orderCaptin/order_speed_request.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../main.dart';
|
||||
import '../../print.dart';
|
||||
import '../../views/notification/notification_captain.dart';
|
||||
import '../home/captin/home_captain_controller.dart';
|
||||
|
||||
class NotificationController extends GetxController {
|
||||
final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
|
||||
@@ -31,10 +32,10 @@ class NotificationController extends GetxController {
|
||||
|
||||
// Create a notification channel
|
||||
const AndroidNotificationChannel channel = AndroidNotificationChannel(
|
||||
'order_channel', // Channel ID
|
||||
'Order Notifications', // Channel name
|
||||
'dynamic_channel', // Channel ID
|
||||
'Dynamic Notifications', // Channel name
|
||||
description:
|
||||
'This channel is used for order notifications.', // Channel description
|
||||
'This channel is used for various types of notifications.', // Channel description
|
||||
importance: Importance.max,
|
||||
);
|
||||
|
||||
@@ -56,7 +57,7 @@ class NotificationController extends GetxController {
|
||||
);
|
||||
|
||||
AndroidNotificationDetails android =
|
||||
AndroidNotificationDetails('order_channel', 'Order Notifications',
|
||||
AndroidNotificationDetails('dynamic_channel', 'Dynamic Notifications',
|
||||
importance: Importance.max,
|
||||
priority: Priority.high,
|
||||
styleInformation: bigTextStyleInformation,
|
||||
@@ -68,6 +69,7 @@ class NotificationController extends GetxController {
|
||||
color: AppColor.primaryColor,
|
||||
showProgress: true,
|
||||
showWhen: true,
|
||||
timeoutAfter: title == 'Order' ? 14500 : 6000,
|
||||
subText: message,
|
||||
actions: [
|
||||
AndroidNotificationAction(
|
||||
@@ -83,42 +85,93 @@ class NotificationController extends GetxController {
|
||||
NotificationDetails details = NotificationDetails(android: android);
|
||||
|
||||
await _flutterLocalNotificationsPlugin.show(0, title, message, details,
|
||||
payload: payLoad);
|
||||
|
||||
// payload: 'order_page_payload');
|
||||
payload: jsonEncode({'title': title, 'data': payLoad}));
|
||||
}
|
||||
|
||||
// Callback when the notification is tapped
|
||||
void onDidReceiveNotificationResponse(NotificationResponse response) {
|
||||
// jsonDecode(response.payload);
|
||||
_handleNotificationResponse(response);
|
||||
}
|
||||
|
||||
// Callback when the notification is tapped while the app is in the background
|
||||
void onDidReceiveBackgroundNotificationResponse(
|
||||
NotificationResponse response) {
|
||||
_handleNotificationResponse(response);
|
||||
}
|
||||
|
||||
// Handle notification response for both foreground and background
|
||||
void _handleNotificationResponse(NotificationResponse response) {
|
||||
print('Notification tapped!');
|
||||
Log.print('response.payload: ${response.payload}');
|
||||
if (response.payload != null) {
|
||||
print('Notification payload: ${response.payload}');
|
||||
// if (response.payload != 'order_page_payload') {
|
||||
// Log.print('arguments: ${box.read(BoxName.rideArguments)}');
|
||||
closeOverLay();
|
||||
Get.to(() => OrderRequestPage(),
|
||||
arguments: {'myListString': response.payload});
|
||||
// }
|
||||
var payloadData = jsonDecode(response.payload.toString());
|
||||
|
||||
if (payloadData is Map<String, dynamic>) {
|
||||
String title = payloadData['title'];
|
||||
var data = payloadData['data'];
|
||||
|
||||
switch (title) {
|
||||
case 'Order':
|
||||
_handleOrderNotification(data);
|
||||
break;
|
||||
case 'OrderSpeed':
|
||||
_handleOrderSpeedNotification(data);
|
||||
break;
|
||||
case 'ADS':
|
||||
_handleADSNotification();
|
||||
break;
|
||||
default:
|
||||
Log.print('Unknown notification type');
|
||||
}
|
||||
} else {
|
||||
Log.print('Invalid payload format');
|
||||
}
|
||||
} else {
|
||||
Log.print('Payload is null');
|
||||
}
|
||||
}
|
||||
|
||||
void _handleOrderNotification(dynamic data) {
|
||||
if (data is String) {
|
||||
var orderData = jsonDecode(data);
|
||||
if (orderData is List && orderData.length == 34) {
|
||||
closeOverLay();
|
||||
Get.put(HomeCaptainController()).changeRideId();
|
||||
Get.to(() => OrderRequestPage(), arguments: {'myListString': data});
|
||||
} else {
|
||||
Log.print('Invalid order data');
|
||||
}
|
||||
} else {
|
||||
Log.print('Invalid order payload');
|
||||
}
|
||||
}
|
||||
|
||||
void _handleOrderSpeedNotification(dynamic data) {
|
||||
if (data is String) {
|
||||
var orderData = jsonDecode(data);
|
||||
if (orderData is List && orderData.length == 34) {
|
||||
closeOverLay();
|
||||
Get.put(HomeCaptainController()).changeRideId();
|
||||
Get.to(() => OrderSpeedRequest(), arguments: {'myListString': data});
|
||||
} else {
|
||||
Log.print('Invalid order data');
|
||||
}
|
||||
} else {
|
||||
Log.print('Invalid order payload');
|
||||
}
|
||||
}
|
||||
|
||||
void _handleADSNotification() {
|
||||
// var orderData = jsonDecode(data);
|
||||
closeOverLay();
|
||||
Get.to(
|
||||
() => const NotificationCaptain(),
|
||||
);
|
||||
}
|
||||
|
||||
void onDidReceiveLocalNotification(
|
||||
int id, String? title, String? body, String? payload) async {
|
||||
// display a dialog with the notification details, tap ok to go to another page
|
||||
}
|
||||
// Callback when the notification is tapped while the app is in the background
|
||||
void onDidReceiveBackgroundNotificationResponse(
|
||||
NotificationResponse response) {
|
||||
print('Notification tapped while app is in background!');
|
||||
if (response.payload != null) {
|
||||
print('Notification payload: ${response.payload}');
|
||||
if (response.payload == 'order') {
|
||||
Get.to(() => OrderRequestPage(),
|
||||
arguments: box.read(BoxName.rideArguments));
|
||||
closeOverLay();
|
||||
Log.print('arguments: ${box.read(BoxName.rideArguments)}');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user