9/11/1
This commit is contained in:
@@ -9,6 +9,7 @@ import 'package:ride/constant/style.dart';
|
||||
import 'package:ride/controller/functions/crud.dart';
|
||||
import 'package:ride/controller/functions/launch.dart';
|
||||
import 'package:ride/controller/functions/toast.dart';
|
||||
import 'package:ride/controller/home/map_page_controller.dart';
|
||||
import 'package:ride/views/home/profile/promos_passenger_page.dart';
|
||||
import 'package:ride/views/widgets/elevated_btn.dart';
|
||||
|
||||
@@ -101,11 +102,13 @@ class FirebasMessagesController extends GetxController {
|
||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
||||
if (message.data.isNotEmpty) {
|
||||
if (message.notification!.title!.contains('Order')) {
|
||||
var myListString = message.data['myList'];
|
||||
var myListString = message.data['DriverList'];
|
||||
print(myListString);
|
||||
print('9999999999999myListString999999999999999');
|
||||
var myList = jsonDecode(myListString) as List<dynamic>;
|
||||
Get.to(() => const OrderRequestPage(), arguments: {
|
||||
Get.to(() => OrderRequestPage(), arguments: {
|
||||
'myListString': myListString,
|
||||
'myList': myList,
|
||||
'DriverList': myList,
|
||||
'body': message.notification!.body
|
||||
});
|
||||
// Get.defaultDialog(
|
||||
@@ -199,6 +202,25 @@ class FirebasMessagesController extends GetxController {
|
||||
// )
|
||||
// ],
|
||||
// ));
|
||||
} else if (message.notification!.title!.contains('Apply Ride')) {
|
||||
// MapController().rideConfirm = true;
|
||||
var passengerList = message.data['passengerList'];
|
||||
print(passengerList);
|
||||
print('9999999999999my Apply Ride 999999999999999');
|
||||
var myList = jsonDecode(passengerList) as List<dynamic>;
|
||||
|
||||
Get.defaultDialog(
|
||||
barrierDismissible: false,
|
||||
title: message.notification!.title.toString(),
|
||||
content: Row(
|
||||
children: [Text(myList[1].toString())],
|
||||
),
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Ok',
|
||||
onPressed: () {
|
||||
// MapController().rideConfirm = true;
|
||||
},
|
||||
));
|
||||
} else if (message.notification!.title!.contains('Promo')) {
|
||||
Get.to(const PromosPassengerPage());
|
||||
}
|
||||
@@ -381,35 +403,58 @@ class FirebasMessagesController extends GetxController {
|
||||
// }
|
||||
// }
|
||||
|
||||
// void sendNotificationDriverId(String title, body, token) async {
|
||||
// http
|
||||
// .post(Uri.parse('https://fcm.googleapis.com/fcm/send'),
|
||||
// headers: <String, String>{
|
||||
// 'Content-Type': 'application/json',
|
||||
// 'Authorization': 'key=${AppCredintials.serverAPI}'
|
||||
// },
|
||||
// body: jsonEncode({
|
||||
// 'notification': <String, dynamic>{
|
||||
// 'title': title,
|
||||
// 'body': body,
|
||||
// 'sound': 'true'
|
||||
// },
|
||||
// 'priority': 'high',
|
||||
// 'data': <String, dynamic>{
|
||||
// 'click_action': 'FLUTTER_NOTIFICATION_CLICK',
|
||||
// 'id': '1',
|
||||
// 'status': 'done'
|
||||
// },
|
||||
// 'to': token,
|
||||
// }))
|
||||
// .whenComplete(() {})
|
||||
// .catchError((e) {
|
||||
// print('sendNotification() error: $e');
|
||||
// });
|
||||
// }
|
||||
void sendNotificanToPassengerToken(
|
||||
String title, body, token, List<String> map) async {
|
||||
try {
|
||||
final response = await http.post(
|
||||
Uri.parse('https://fcm.googleapis.com/fcm/send'),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'key=${AppCredintials.serverAPI}'
|
||||
},
|
||||
body: jsonEncode({
|
||||
'notification': <String, dynamic>{
|
||||
'title': title,
|
||||
'body': body,
|
||||
'sound': 'true'
|
||||
},
|
||||
'data': {
|
||||
'passengerList': map,
|
||||
},
|
||||
'priority': 'high',
|
||||
'to': token,
|
||||
}),
|
||||
);
|
||||
|
||||
void sendNotificationDriverId(String title, body, strin1, strin2, strin3,
|
||||
strin4, strin5, strin6, string7, string8, token) async {
|
||||
if (response.statusCode == 200) {
|
||||
// Notification sent successfully
|
||||
print('Notification sent successfully');
|
||||
} else {
|
||||
// Handle error response
|
||||
print(
|
||||
'Failed to send notification. Status code: ${response.statusCode}');
|
||||
}
|
||||
} catch (e) {
|
||||
// Handle other exceptions
|
||||
print('sendNotification() error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
void sendNotificationToDriverId(
|
||||
String title,
|
||||
body,
|
||||
strin1,
|
||||
strin2,
|
||||
strin3,
|
||||
strin4,
|
||||
strin5,
|
||||
strin6,
|
||||
string7,
|
||||
string8,
|
||||
passengerName,
|
||||
passengertoken,
|
||||
passengerPhone,
|
||||
token) async {
|
||||
http
|
||||
.post(Uri.parse('https://fcm.googleapis.com/fcm/send'),
|
||||
headers: <String, String>{
|
||||
@@ -431,7 +476,10 @@ class FirebasMessagesController extends GetxController {
|
||||
strin5,
|
||||
strin6,
|
||||
string7,
|
||||
string8
|
||||
string8,
|
||||
passengerName,
|
||||
passengertoken,
|
||||
passengerPhone
|
||||
]),
|
||||
},
|
||||
'priority': 'high',
|
||||
@@ -442,4 +490,41 @@ class FirebasMessagesController extends GetxController {
|
||||
print('sendNotification() error: $e');
|
||||
});
|
||||
}
|
||||
|
||||
void sendNotificationToDriverMAP(
|
||||
String title, String body, String token, List<String> data) async {
|
||||
try {
|
||||
final response = await http.post(
|
||||
Uri.parse('https://fcm.googleapis.com/fcm/send'),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'key=${AppCredintials.serverAPI}'
|
||||
},
|
||||
body: jsonEncode({
|
||||
'notification': <String, dynamic>{
|
||||
'title': title,
|
||||
'body': body,
|
||||
'sound': 'true'
|
||||
},
|
||||
'data': {
|
||||
'DriverList': data,
|
||||
},
|
||||
'priority': 'high',
|
||||
'to': token,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
// Notification sent successfully
|
||||
print('Notification sent successfully');
|
||||
} else {
|
||||
// Handle error response
|
||||
print(
|
||||
'Failed to send notification. Status code: ${response.statusCode}');
|
||||
}
|
||||
} catch (e) {
|
||||
// Handle other exceptions
|
||||
print('sendNotification() error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ class CRUD {
|
||||
},
|
||||
);
|
||||
print(response.request);
|
||||
print(payload);
|
||||
|
||||
var jsonData = jsonDecode(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
@@ -31,8 +31,8 @@ class LocationController extends GetxController {
|
||||
|
||||
await CRUD().post(link: AppLink.addCarsLocationByPassenger, payload: {
|
||||
'driver_id': box.read(BoxName.driverID).toString(),
|
||||
'latitude': mylocation!.latitude.toString(),
|
||||
'longitude': mylocation!.longitude.toString(),
|
||||
'latitude': mylocation.latitude.toString(),
|
||||
'longitude': mylocation.longitude.toString(),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
42
lib/controller/home/captin/order_request_controller.dart
Normal file
42
lib/controller/home/captin/order_request_controller.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:ride/constant/links.dart';
|
||||
|
||||
import '../../functions/crud.dart';
|
||||
|
||||
class TimerController extends GetxController {
|
||||
double progress = 0;
|
||||
int duration = 25;
|
||||
int remainingTime = 0;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
startTimer();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
void startTimer() async {
|
||||
for (int i = 0; i <= duration; i++) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
progress = i / duration;
|
||||
remainingTime = duration - i;
|
||||
|
||||
update();
|
||||
}
|
||||
timerEnded();
|
||||
}
|
||||
|
||||
void refuseOrder(String driverID, orderID) async {
|
||||
await CRUD().postFromDialogue(link: AppLink.addDriverOrder, payload: {
|
||||
'driver_id': driverID,
|
||||
// box.read(BoxName.driverID).toString(),
|
||||
'order_id': orderID,
|
||||
'status': 'Refused'
|
||||
});
|
||||
Get.back();
|
||||
}
|
||||
|
||||
void timerEnded() async {
|
||||
print('Timer ended');
|
||||
// refuseOrder();
|
||||
}
|
||||
}
|
||||
@@ -126,12 +126,12 @@ class MapController extends GetxController {
|
||||
}
|
||||
|
||||
changeConfirmRide() async {
|
||||
rideConfirm = true;
|
||||
print('rideConfirm= $rideConfirm');
|
||||
|
||||
// rideConfirm = true;
|
||||
// update();
|
||||
// print('rideConfirm= $rideConfirm');
|
||||
await getCarsLocationByPassenger();
|
||||
await CRUD().post(link: AppLink.addRides, payload: {
|
||||
"start_location": '${data[0]['start_address']}',
|
||||
|
||||
// '${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
|
||||
"end_location": '${data[0]['end_address']}',
|
||||
// '${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
|
||||
@@ -147,6 +147,7 @@ class MapController extends GetxController {
|
||||
"distance": distance.toString()
|
||||
}).then((value) {
|
||||
// print(jsonDecode(value)['message']);
|
||||
// List<String> body = [
|
||||
List<String> body = [
|
||||
// '${data[0]['start_address']}',
|
||||
// '${data[0]['end_address']}',
|
||||
@@ -157,21 +158,37 @@ class MapController extends GetxController {
|
||||
duration.toString(),
|
||||
distance.toString(),
|
||||
dataCarsLocationByPassenger['message'][0]['id'].toString(),
|
||||
box.read(BoxName.pasengerID).toString()
|
||||
box.read(BoxName.pasengerID).toString(),
|
||||
box.read(BoxName.name).toString(),
|
||||
box.read(BoxName.tokenFCM).toString(),
|
||||
box.read(BoxName.phone).toString(),
|
||||
duratioByPassenger.toString(),
|
||||
distanceByPassenger.toString(),
|
||||
];
|
||||
FirebasMessagesController().sendNotificationDriverId(
|
||||
FirebasMessagesController().sendNotificationToDriverMAP(
|
||||
'Order',
|
||||
jsonDecode(value)['message'].toString(),
|
||||
body[0],
|
||||
body[1],
|
||||
body[2],
|
||||
body[3],
|
||||
body[4],
|
||||
body[5],
|
||||
body[6],
|
||||
body[7],
|
||||
box.read(BoxName.tokenFCM).toString(), //TODO change to Driver
|
||||
dataCarsLocationByPassenger['message'][0]['token'].toString(),
|
||||
body,
|
||||
);
|
||||
// FirebasMessagesController().sendNotificationToDriverId(
|
||||
// 'Order',
|
||||
// jsonDecode(value)['message'].toString(),
|
||||
// body[0],
|
||||
// body[1],
|
||||
// body[2],
|
||||
// body[3],
|
||||
// body[4],
|
||||
// body[5],
|
||||
// body[6],
|
||||
// body[7],
|
||||
// body[8],
|
||||
// body[9],
|
||||
// body[10],
|
||||
// dataCarsLocationByPassenger['message'][0]['token'].toString(),
|
||||
// );
|
||||
print(dataCarsLocationByPassenger);
|
||||
print(dataCarsLocationByPassenger['message'][0]['token'].toString());
|
||||
});
|
||||
|
||||
update();
|
||||
@@ -372,7 +389,7 @@ class MapController extends GetxController {
|
||||
|
||||
LatLngBounds calculateBounds(
|
||||
double centerLat, double centerLng, double radius) {
|
||||
double radius = 2000; // 10 km in meters
|
||||
double radius = 4000; // 10 km in meters
|
||||
|
||||
southwest = LatLng(
|
||||
centerLat - (radius / 111000),
|
||||
@@ -449,6 +466,7 @@ class MapController extends GetxController {
|
||||
}
|
||||
|
||||
String duratioByPassenger = '';
|
||||
String distanceByPassenger = '';
|
||||
void getNearestDriverByPassengerLocation() async {
|
||||
if (polylines.isEmpty || data.isEmpty) {
|
||||
double nearestDistance = double.infinity;
|
||||
@@ -471,7 +489,7 @@ class MapController extends GetxController {
|
||||
// longitude: double.parse(carLocation['longitude']),
|
||||
// );
|
||||
// }
|
||||
isloading = true;
|
||||
// isloading = true;
|
||||
update();
|
||||
// Make API request to get exact distance and duration
|
||||
String apiUrl =
|
||||
@@ -481,6 +499,8 @@ class MapController extends GetxController {
|
||||
var data = response;
|
||||
// Extract distance and duration from the response and handle accordingly
|
||||
int distance1 = data['rows'][0]['elements'][0]['distance']['value'];
|
||||
distanceByPassenger =
|
||||
data['rows'][0]['elements'][0]['distance']['text'];
|
||||
duration1 = data['rows'][0]['elements'][0]['duration']['value'];
|
||||
duratioByPassenger =
|
||||
data['rows'][0]['elements'][0]['duration']['text'];
|
||||
@@ -495,7 +515,7 @@ class MapController extends GetxController {
|
||||
latitude: double.parse(carLocation['latitude']),
|
||||
longitude: double.parse(carLocation['longitude']),
|
||||
);
|
||||
isloading = false;
|
||||
// isloading = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user