7/31/1
This commit is contained in:
18
lib/controller/firebase/bring_app_foreground.dart
Normal file
18
lib/controller/firebase/bring_app_foreground.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class AppLifecycleManager {
|
||||
static const platform = MethodChannel('com.sefer_driver/app_lifecycle');
|
||||
|
||||
static Future<void> bringAppToForeground() async {
|
||||
try {
|
||||
debugPrint('Attempting to bring app to foreground');
|
||||
await platform.invokeMethod('bringAppToForeground');
|
||||
debugPrint('Method invocation completed');
|
||||
} on PlatformException catch (e) {
|
||||
debugPrint("Failed to bring app to foreground: '${e.message}'.");
|
||||
} catch (e) {
|
||||
debugPrint("Unexpected error: $e");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:SEFER/controller/home/captin/home_captain_controller.dart';
|
||||
import 'package:SEFER/views/home/Captin/home_captain/widget/call_page.dart';
|
||||
import 'package:SEFER/views/widgets/mydialoug.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -79,9 +78,27 @@ class FirebaseMessagesController extends GetxController {
|
||||
}
|
||||
});
|
||||
FirebaseMessaging.onBackgroundMessage((RemoteMessage message) async {
|
||||
// Handle background message
|
||||
if (message.data.isNotEmpty && message.notification != null) {
|
||||
fireBaseTitles(message);
|
||||
if (message.notification!.title! == 'Order'.tr) {
|
||||
if (Platform.isAndroid) {
|
||||
NotificationController()
|
||||
.showNotification('Order'.tr, '', 'order', 'order_page_payload');
|
||||
}
|
||||
// await FirebaseMessagesController().showOverlayNotification(message);
|
||||
var myListString = message.data['DriverList'];
|
||||
// var points = message.data['PolylineJson'];
|
||||
|
||||
var myList = jsonDecode(myListString) as List<dynamic>;
|
||||
// var myPoints = jsonDecode(points) as List<dynamic>;
|
||||
driverToken = myList[14].toString();
|
||||
// This is for location using and uploading status
|
||||
Get.put(HomeCaptainController()).changeRideId();
|
||||
update();
|
||||
Get.to(() => OrderRequestPage(), arguments: {
|
||||
'myListString': myListString,
|
||||
'DriverList': myList,
|
||||
// 'PolylineJson': myPoints,
|
||||
'body': message.notification!.body
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -95,8 +112,9 @@ class FirebaseMessagesController extends GetxController {
|
||||
Future<void> fireBaseTitles(RemoteMessage message) async {
|
||||
if (message.notification!.title! == 'Order'.tr) {
|
||||
if (Platform.isAndroid) {
|
||||
NotificationController().showNotification('Order'.tr, '', 'order');
|
||||
NotificationController().showNotification('Order'.tr, '', 'order', '');
|
||||
}
|
||||
// await FirebaseMessagesController().showOverlayNotification(message);
|
||||
var myListString = message.data['DriverList'];
|
||||
// var points = message.data['PolylineJson'];
|
||||
|
||||
@@ -113,8 +131,10 @@ class FirebaseMessagesController extends GetxController {
|
||||
'body': message.notification!.body
|
||||
});
|
||||
} else if (message.notification!.title == 'Cancel Trip') {
|
||||
NotificationController().showNotification(
|
||||
'Cancel Trip'.tr, 'Passenger Cancel Trip'.tr, 'cancel');
|
||||
// if (Platform.isAndroid) {
|
||||
// NotificationController().showNotification(
|
||||
// 'Cancel Trip'.tr, 'Passenger Cancel Trip'.tr, 'cancel', '');
|
||||
// }
|
||||
cancelTripDialog();
|
||||
} else if (message.notification!.title! == 'token change') {
|
||||
// NotificationController()
|
||||
@@ -122,14 +142,18 @@ class FirebaseMessagesController extends GetxController {
|
||||
// GoogleSignInHelper.signOut();
|
||||
GoogleSignInHelper.signOut();
|
||||
} else if (message.notification!.title! == 'message From passenger') {
|
||||
NotificationController()
|
||||
.showNotification('message From passenger', ''.tr, 'tone2');
|
||||
if (Platform.isAndroid) {
|
||||
NotificationController()
|
||||
.showNotification('message From passenger', ''.tr, 'tone2', '');
|
||||
}
|
||||
passengerDialog(message.notification!.body!);
|
||||
|
||||
update();
|
||||
} else if (message.notification!.title! == 'face detect') {
|
||||
NotificationController()
|
||||
.showNotification('face detect'.tr, ''.tr, 'tone2');
|
||||
if (Platform.isAndroid) {
|
||||
NotificationController()
|
||||
.showNotification('face detect'.tr, ''.tr, 'tone2', '');
|
||||
}
|
||||
String result0 = await faceDetector();
|
||||
// Handle the result here, e.g., show a dialog or update the UI
|
||||
var result = jsonDecode(result0);
|
||||
@@ -156,19 +180,20 @@ class FirebaseMessagesController extends GetxController {
|
||||
} else if (message.notification!.title! == 'Hi ,I will go now') {
|
||||
// Get.snackbar('Hi ,I will go now', '',
|
||||
// backgroundColor: AppColor.greenColor);
|
||||
NotificationController().showNotification(
|
||||
'Passenger come to you'.tr, 'Hi ,I will go now'.tr, 'tone2');
|
||||
if (Platform.isAndroid) {
|
||||
NotificationController().showNotification(
|
||||
'Passenger come to you'.tr, 'Hi ,I will go now'.tr, 'tone2', '');
|
||||
}
|
||||
update();
|
||||
} else if (message.notification!.title! == 'Call Income'.tr) {
|
||||
try {
|
||||
var myListString = message.data['passengerList'];
|
||||
var driverList = jsonDecode(myListString) as List<dynamic>;
|
||||
// if (Platform.isAndroid) {
|
||||
NotificationController().showNotification(
|
||||
'Call Income'.tr,
|
||||
message.notification!.body!,
|
||||
'iphone_ringtone',
|
||||
);
|
||||
if (Platform.isAndroid) {
|
||||
NotificationController().showNotification('Call Income'.tr,
|
||||
message.notification!.body!, 'iphone_ringtone', '');
|
||||
}
|
||||
// }
|
||||
// Assuming GetMaterialApp is initialized and context is valid for navigation
|
||||
// Get.to(() => PassengerCallPage(
|
||||
@@ -183,11 +208,10 @@ class FirebaseMessagesController extends GetxController {
|
||||
var myListString = message.data['passengerList'];
|
||||
var driverList = jsonDecode(myListString) as List<dynamic>;
|
||||
// if (Platform.isAndroid) {
|
||||
NotificationController().showNotification(
|
||||
'Call Income'.tr,
|
||||
message.notification!.body!,
|
||||
'iphone_ringtone',
|
||||
);
|
||||
if (Platform.isAndroid) {
|
||||
NotificationController().showNotification('Call Income'.tr,
|
||||
message.notification!.body!, 'iphone_ringtone', '');
|
||||
}
|
||||
// }
|
||||
// Assuming GetMaterialApp is initialized and context is valid for navigation
|
||||
// Get.to(() => CallPage(
|
||||
@@ -198,11 +222,13 @@ class FirebaseMessagesController extends GetxController {
|
||||
} catch (e) {}
|
||||
} else if (message.notification!.title! ==
|
||||
"Criminal Document Required".tr) {
|
||||
NotificationController().showNotification(
|
||||
"Criminal Document Required".tr,
|
||||
message.notification!.body!,
|
||||
'tone2',
|
||||
);
|
||||
if (Platform.isAndroid) {
|
||||
NotificationController().showNotification(
|
||||
"Criminal Document Required".tr,
|
||||
message.notification!.body!,
|
||||
'tone2',
|
||||
'');
|
||||
}
|
||||
MyDialog().getDialog(
|
||||
"Criminal Document Required".tr, 'You should have upload it .'.tr,
|
||||
() {
|
||||
@@ -215,10 +241,7 @@ class FirebaseMessagesController extends GetxController {
|
||||
var driverList = jsonDecode(myListString) as List<dynamic>;
|
||||
if (Platform.isAndroid) {
|
||||
NotificationController().showNotification(
|
||||
'Call End'.tr,
|
||||
message.notification!.body!,
|
||||
'tone2',
|
||||
);
|
||||
'Call End'.tr, message.notification!.body!, 'tone2', '');
|
||||
}
|
||||
// Assuming GetMaterialApp is initialized and context is valid for navigation
|
||||
// Get.off(const CallPage());
|
||||
@@ -247,11 +270,14 @@ class FirebaseMessagesController extends GetxController {
|
||||
'body': message.notification!.body
|
||||
});
|
||||
} else if (message.notification!.title! == 'Order Applied'.tr) {
|
||||
NotificationController().showNotification(
|
||||
'The order Accepted by another Driver'.tr,
|
||||
'We regret to inform you that another driver has accepted this order.'
|
||||
.tr,
|
||||
'order');
|
||||
if (Platform.isAndroid) {
|
||||
NotificationController().showNotification(
|
||||
'The order Accepted by another Driver'.tr,
|
||||
'We regret to inform you that another driver has accepted this order.'
|
||||
.tr,
|
||||
'order',
|
||||
'');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -623,3 +649,34 @@ class FirebaseMessagesController extends GetxController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class OverlayContent extends StatelessWidget {
|
||||
final String title;
|
||||
final String body;
|
||||
|
||||
OverlayContent(this.title, this.body);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
color: Colors.white,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
),
|
||||
SizedBox(height: 8.0),
|
||||
Text(
|
||||
body,
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +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:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../main.dart';
|
||||
import '../../print.dart';
|
||||
|
||||
class NotificationController extends GetxController {
|
||||
final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
|
||||
FlutterLocalNotificationsPlugin();
|
||||
@@ -8,22 +17,108 @@ class NotificationController extends GetxController {
|
||||
// Initializes the local notifications plugin
|
||||
Future<void> initNotifications() async {
|
||||
const AndroidInitializationSettings android =
|
||||
AndroidInitializationSettings('@mipmap/launcher_icon');
|
||||
AndroidInitializationSettings('app_icon');
|
||||
|
||||
const InitializationSettings initializationSettings =
|
||||
InitializationSettings(android: android);
|
||||
await _flutterLocalNotificationsPlugin.initialize(initializationSettings);
|
||||
|
||||
await _flutterLocalNotificationsPlugin.initialize(
|
||||
initializationSettings,
|
||||
onDidReceiveNotificationResponse: onDidReceiveNotificationResponse,
|
||||
onDidReceiveBackgroundNotificationResponse:
|
||||
onDidReceiveBackgroundNotificationResponse,
|
||||
);
|
||||
|
||||
// Create a notification channel
|
||||
const AndroidNotificationChannel channel = AndroidNotificationChannel(
|
||||
'order_channel', // Channel ID
|
||||
'Order Notifications', // Channel name
|
||||
description:
|
||||
'This channel is used for order notifications.', // Channel description
|
||||
importance: Importance.max,
|
||||
);
|
||||
|
||||
// Register the channel with the system
|
||||
await _flutterLocalNotificationsPlugin
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin>()
|
||||
?.createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
// Displays a notification with the given title and message
|
||||
void showNotification(String title, String message, String tone) async {
|
||||
AndroidNotificationDetails android = AndroidNotificationDetails(
|
||||
'your channel id', 'your channel name',
|
||||
importance: Importance.max,
|
||||
priority: Priority.high,
|
||||
showWhen: false,
|
||||
sound: RawResourceAndroidNotificationSound(tone));
|
||||
void showNotification(
|
||||
String title, String message, String tone, String payLoad) async {
|
||||
BigTextStyleInformation bigTextStyleInformation = BigTextStyleInformation(
|
||||
message,
|
||||
contentTitle: title.tr,
|
||||
htmlFormatContent: true,
|
||||
htmlFormatContentTitle: true,
|
||||
);
|
||||
|
||||
AndroidNotificationDetails android =
|
||||
AndroidNotificationDetails('order_channel', 'Order Notifications',
|
||||
importance: Importance.max,
|
||||
priority: Priority.high,
|
||||
styleInformation: bigTextStyleInformation,
|
||||
playSound: true,
|
||||
sound: RawResourceAndroidNotificationSound(tone),
|
||||
audioAttributesUsage: AudioAttributesUsage.alarm,
|
||||
visibility: NotificationVisibility.public,
|
||||
autoCancel: false,
|
||||
color: AppColor.primaryColor,
|
||||
showProgress: true,
|
||||
showWhen: true,
|
||||
subText: message,
|
||||
actions: [
|
||||
AndroidNotificationAction(
|
||||
allowGeneratedReplies: true,
|
||||
'id',
|
||||
title.tr,
|
||||
titleColor: AppColor.bronze,
|
||||
showsUserInterface: true,
|
||||
)
|
||||
],
|
||||
category: AndroidNotificationCategory.call);
|
||||
|
||||
NotificationDetails details = NotificationDetails(android: android);
|
||||
await _flutterLocalNotificationsPlugin.show(0, title, message, details);
|
||||
|
||||
await _flutterLocalNotificationsPlugin.show(0, title, message, details,
|
||||
payload: payLoad);
|
||||
|
||||
// payload: 'order_page_payload');
|
||||
}
|
||||
|
||||
// Callback when the notification is tapped
|
||||
void onDidReceiveNotificationResponse(NotificationResponse response) {
|
||||
// jsonDecode(response.payload);
|
||||
print('Notification tapped!');
|
||||
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});
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
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)}');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
37
lib/controller/firebase/order_lay.dart
Normal file
37
lib/controller/firebase/order_lay.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
import 'package:SEFER/constant/links.dart';
|
||||
import 'package:SEFER/controller/functions/crud.dart';
|
||||
import 'package:SEFER/views/home/Captin/home_captain/home_captin.dart';
|
||||
import 'package:SEFER/views/home/Captin/orderCaptin/order_request_page.dart';
|
||||
import 'package:SEFER/views/widgets/elevated_btn.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class OverlayContent1 extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
color: Colors.white,
|
||||
child: MyElevatedButton(
|
||||
title: 'go to order',
|
||||
onPressed: () async {
|
||||
var res = await CRUD().post(
|
||||
link: AppLink.addFeedBack,
|
||||
payload: {
|
||||
"passengerId": 'dddddd',
|
||||
"feedBack": "eeeee",
|
||||
},
|
||||
);
|
||||
print(res);
|
||||
if (res != 'failure') {
|
||||
Navigator.push(
|
||||
context, MaterialPageRoute(builder: (cont) => HomeCaptain()));
|
||||
// Get.to(OrderRequestPage());
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user