8-24/1
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 7.5 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 242 KiB After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 242 KiB After Width: | Height: | Size: 152 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 7.5 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 8.2 KiB |
|
Before Width: | Height: | Size: 718 B After Width: | Height: | Size: 489 B |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 9.2 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 1011 B After Width: | Height: | Size: 584 B |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 923 B |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1021 B |
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 7.4 KiB After Width: | Height: | Size: 3.7 KiB |
@@ -108,7 +108,5 @@ class LoginController extends GetxController {
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
FirebasMessagesController().requestPermission();
|
||||
// goToMapPage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,52 +22,30 @@ class FirebasMessagesController extends GetxController {
|
||||
super.onInit();
|
||||
// getNotificationSettings();
|
||||
getToken();
|
||||
getTokens();
|
||||
await getTokens();
|
||||
}
|
||||
|
||||
Future<void> getNotificationSettings() async {
|
||||
// Get the current notification settings.
|
||||
notificationSettings =
|
||||
// Get the current notification settings
|
||||
NotificationSettings? notificationSettings =
|
||||
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",
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
print(
|
||||
'Notification authorization status: ${notificationSettings.authorizationStatus}');
|
||||
|
||||
// Call the update function if needed
|
||||
update();
|
||||
}
|
||||
|
||||
Future checkAndRequestPermission() async {
|
||||
if (notificationSettings!.authorizationStatus ==
|
||||
AuthorizationStatus.denied) {
|
||||
await requestPermission();
|
||||
}
|
||||
}
|
||||
Future<void> requestFirebaseMessagingPermission() async {
|
||||
FirebaseMessaging messaging = FirebaseMessaging.instance;
|
||||
|
||||
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) {
|
||||
print('dddddddddddddddddddddd');
|
||||
}
|
||||
print(value.authorizationStatus);
|
||||
});
|
||||
} else {
|
||||
await messaging.requestPermission();
|
||||
} else if (Platform.isIOS) {
|
||||
// Request permission for iOS
|
||||
NotificationSettings settings = await fcmToken.requestPermission(
|
||||
NotificationSettings settings = await messaging.requestPermission(
|
||||
alert: true,
|
||||
announcement: true,
|
||||
badge: true,
|
||||
@@ -77,7 +55,7 @@ class FirebasMessagesController extends GetxController {
|
||||
sound: true,
|
||||
);
|
||||
print('User granted permission: ${settings.authorizationStatus}');
|
||||
fcmToken.setForegroundNotificationPresentationOptions(
|
||||
messaging.setForegroundNotificationPresentationOptions(
|
||||
alert: true, badge: true, sound: true);
|
||||
}
|
||||
}
|
||||
@@ -107,68 +85,42 @@ class FirebasMessagesController extends GetxController {
|
||||
}
|
||||
|
||||
void getToken() async {
|
||||
// final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
await fcmToken.getToken().then(
|
||||
(token) {
|
||||
box.write(BoxName.tokenFCM, token);
|
||||
print(box.read(BoxName.tokenFCM).toString());
|
||||
},
|
||||
);
|
||||
FirebaseMessaging.onMessage.listen((event) {
|
||||
await fcmToken.getToken().then((token) {
|
||||
box.write(BoxName.tokenFCM, token);
|
||||
print(token);
|
||||
});
|
||||
|
||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
||||
print(
|
||||
'onMessage: ${event.notification!.title} ${event.notification!.body}');
|
||||
'onMessage: ${message.notification!.title} ${message.notification!.body}');
|
||||
if (Get.currentRoute == '/') {
|
||||
// If the app is in the foreground, show a dialog to the user
|
||||
if (event.notification!.title.toString().contains('ride')) {
|
||||
if (message.notification!.title!.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
|
||||
.toString()
|
||||
.contains('تعديل طلبيات')) {}
|
||||
} else if (event.notification!.title.toString().contains('Deleted')) {
|
||||
// LogOutController().removeKeys(prefs);
|
||||
}
|
||||
} else {
|
||||
// If the app is in the background or terminated, show a system tray message
|
||||
RemoteNotification? notification = event.notification;
|
||||
AndroidNotification? android = event.notification?.android;
|
||||
// if (notification != null && android != null) {
|
||||
RemoteNotification? notification = message.notification;
|
||||
AndroidNotification? android = message.notification?.android;
|
||||
if (notification != null && android != null) {
|
||||
print(
|
||||
'onMessageOpenedApp: ${notification.title} ${notification.body}');
|
||||
if (event.notification!.title.toString().contains('ride')) {
|
||||
if (message.notification!.title!.contains('ride')) {
|
||||
Get.snackbar('ride', 'message', backgroundColor: AppColor.redColor);
|
||||
// SendGpsNow().getSiteNotification();
|
||||
} else if (event.notification!.title.toString().contains('انذار')) {
|
||||
// Get.to(() => const ProfilePage());
|
||||
} else if (event.notification!.title
|
||||
.toString()
|
||||
.contains('تعديل طلبيات')) {
|
||||
// Get.to(() => const OrdersDriverPage());
|
||||
} else if (event.notification!.title.toString().contains('Deleted')) {
|
||||
// LogOutController().removeKeys(prefs);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage event) {
|
||||
|
||||
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
|
||||
print(
|
||||
'onMessageOpenedApp: ${event.notification!.title} ${event.notification!.body}');
|
||||
RemoteNotification? notification = event.notification;
|
||||
'onMessageOpenedApp: ${message.notification!.title} ${message.notification!.body}');
|
||||
RemoteNotification? notification = message.notification;
|
||||
if (notification != null) {
|
||||
print('onMessageOpenedApp: ${notification.title} ${notification.body}');
|
||||
|
||||
if (event.notification!.title.toString().contains('ride')) {
|
||||
if (message.notification!.title!.contains('ride')) {
|
||||
Get.snackbar('ride', 'message', backgroundColor: AppColor.redColor);
|
||||
// SendGpsNow().getSiteNotification();
|
||||
} else if (event.notification!.title.toString().contains('انذار')) {
|
||||
// Get.to(() => const ProfilePage());
|
||||
} else if (event.notification!.title
|
||||
.toString()
|
||||
.contains('تعديل طلبيات')) {
|
||||
// Get.to(() => const OrdersDriverPage());
|
||||
} else if (event.notification!.title.toString().contains('Deleted')) {
|
||||
// LogOutController().removeKeys(prefs);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -213,61 +165,61 @@ class FirebasMessagesController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
void sendNotificationToManager(String title, body) async {
|
||||
// tokens = box.read(BoxName.tokenManager);
|
||||
// void sendNotificationToManager(String title, body) async {
|
||||
// // tokens = box.read(BoxName.tokenManager);
|
||||
|
||||
for (var i = 0; i < tokens.length; i++) {
|
||||
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': tokens[i],
|
||||
}))
|
||||
.whenComplete(() {})
|
||||
.catchError((e) {
|
||||
print('sendNotification() error: $e');
|
||||
});
|
||||
}
|
||||
}
|
||||
// for (var i = 0; i < tokens.length; i++) {
|
||||
// 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': tokens[i],
|
||||
// }))
|
||||
// .whenComplete(() {})
|
||||
// .catchError((e) {
|
||||
// print('sendNotification() error: $e');
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
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 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');
|
||||
// });
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -22,10 +22,11 @@ class CRUD {
|
||||
},
|
||||
);
|
||||
// print("--------------" + response.body.toString());
|
||||
// print("--------------" + payload.toString());
|
||||
if (response.statusCode == 200) {
|
||||
var jsonData = jsonDecode(response.body);
|
||||
if (jsonData['status'] == 'success') {
|
||||
print(jsonData);
|
||||
// print(jsonData);
|
||||
return response.body;
|
||||
}
|
||||
return jsonData['status'];
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:math' show sqrt, pi, cos, sin;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:google_polyline_algorithm/google_polyline_algorithm.dart';
|
||||
@@ -9,10 +11,9 @@ import 'package:ride/constant/box_name.dart';
|
||||
import 'package:ride/constant/credential.dart';
|
||||
import 'package:ride/constant/links.dart';
|
||||
import 'package:ride/controller/functions/crud.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:ride/views/widgets/elevated_btn.dart';
|
||||
import '../../main.dart';
|
||||
import '../../models/model/locations.dart';
|
||||
import '../firebase/firbase_messge.dart';
|
||||
|
||||
class MapController extends GetxController {
|
||||
bool isloading = true;
|
||||
@@ -27,7 +28,7 @@ class MapController extends GetxController {
|
||||
late LatLng newMylocation = const LatLng(32.115295, 36.064773);
|
||||
LatLng mydestination = const LatLng(32.115295, 36.064773);
|
||||
final List<LatLng> polylineCoordinates = [];
|
||||
final List<LatLng> carsLocationByPassenger = [];
|
||||
List<LatLng> carsLocationByPassenger = [];
|
||||
BitmapDescriptor markerIcon = BitmapDescriptor.defaultMarker;
|
||||
BitmapDescriptor carIcon = BitmapDescriptor.defaultMarker;
|
||||
double height = 150;
|
||||
@@ -43,14 +44,17 @@ class MapController extends GetxController {
|
||||
bool isCancelRidePageShown = false;
|
||||
bool isCashConfirmPageShown = false;
|
||||
bool isPaymentMethodPageShown = false;
|
||||
bool rideConfirm = false;
|
||||
bool isMainBottomMenuMap = true;
|
||||
double heightButtomSheetShown = 0;
|
||||
double cashConfirmPageShown = 250;
|
||||
double paymentPageShown = Get.height * .6;
|
||||
late final LatLng southwest;
|
||||
late final LatLng northeast;
|
||||
late LatLng southwest;
|
||||
late LatLng northeast;
|
||||
List<CarLocationModel> carLocations = <CarLocationModel>[];
|
||||
|
||||
var dataCarsLocationByPassenger;
|
||||
CarLocation? nearestCar;
|
||||
late Timer markerReloadingTimer;
|
||||
// final mainBottomMenuMap = GlobalKey<AnimatedContainer>();
|
||||
void changeButtomSheetShown() {
|
||||
isButtomSheetShown = !isButtomSheetShown;
|
||||
@@ -103,24 +107,15 @@ class MapController extends GetxController {
|
||||
update();
|
||||
}
|
||||
|
||||
bool rideConfirm = false;
|
||||
changeConfirmRide() {
|
||||
rideConfirm = true;
|
||||
print('rideConfirm= $rideConfirm');
|
||||
//TODO add ride and get ride id and details
|
||||
update();
|
||||
}
|
||||
|
||||
Future cancelRide() async {
|
||||
var payload = {
|
||||
"driverID": "1", // Convert to String
|
||||
"passengerID":
|
||||
box.read(BoxName.pasengerID).toString(), // Convert to String
|
||||
"rideID": "222", // Convert to String
|
||||
"note": cancelNote
|
||||
};
|
||||
|
||||
print(rideConfirm);
|
||||
print(payload);
|
||||
|
||||
if (rideConfirm == false) {
|
||||
clearPlaces();
|
||||
@@ -134,7 +129,13 @@ class MapController extends GetxController {
|
||||
data = [];
|
||||
changeCancelRidePageShow();
|
||||
|
||||
await CRUD().post(link: AppLink.addCancelRide, payload: payload);
|
||||
await CRUD().post(link: AppLink.addCancelRide, payload: {
|
||||
"driverID": "1", // Convert to String
|
||||
"passengerID":
|
||||
box.read(BoxName.pasengerID).toString(), // Convert to String
|
||||
"rideID": "222", // Convert to String
|
||||
"note": cancelNote
|
||||
});
|
||||
|
||||
update();
|
||||
}
|
||||
@@ -244,7 +245,7 @@ class MapController extends GetxController {
|
||||
}
|
||||
|
||||
// Configure location accuracy
|
||||
LocationAccuracy desiredAccuracy = LocationAccuracy.high;
|
||||
// LocationAccuracy desiredAccuracy = LocationAccuracy.high;
|
||||
|
||||
// Get the current location
|
||||
LocationData _locationData = await location.getLocation();
|
||||
@@ -263,6 +264,7 @@ class MapController extends GetxController {
|
||||
}
|
||||
|
||||
Future getCarsLocationByPassenger() async {
|
||||
carsLocationByPassenger = [];
|
||||
LatLngBounds bounds =
|
||||
calculateBounds(mylocation.latitude, mylocation.longitude, 10);
|
||||
print(
|
||||
@@ -277,15 +279,29 @@ class MapController extends GetxController {
|
||||
'northeastLat': northeast.latitude.toString(),
|
||||
'northeastLon': northeast.longitude.toString(),
|
||||
});
|
||||
var data = jsonDecode(res);
|
||||
// print(data);
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
carsLocationByPassenger.add(LatLng(
|
||||
double.parse(data['message'][i]['latitude']),
|
||||
double.parse(data['message'][i]['longitude'])));
|
||||
}
|
||||
if (res == 'failure') {
|
||||
Get.defaultDialog(
|
||||
title: 'No Car in your site.Sorry!',
|
||||
middleText: '',
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Back',
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
markerReloadingTimer.cancel();
|
||||
}));
|
||||
} else {
|
||||
dataCarsLocationByPassenger = jsonDecode(res);
|
||||
// print(dataCarsLocationByPassenger);
|
||||
|
||||
update();
|
||||
for (var i = 0; i < dataCarsLocationByPassenger['message'].length; i++) {
|
||||
carsLocationByPassenger.add(LatLng(
|
||||
double.parse(dataCarsLocationByPassenger['message'][i]['latitude']),
|
||||
double.parse(
|
||||
dataCarsLocationByPassenger['message'][i]['longitude'])));
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
LatLngBounds calculateBounds(
|
||||
@@ -315,6 +331,120 @@ class MapController extends GetxController {
|
||||
update();
|
||||
}
|
||||
|
||||
// void startMarkerReloading() {
|
||||
// markerReloadingTimer = Timer.periodic(const Duration(seconds: 30), (timer) {
|
||||
// print('timer==============================');
|
||||
// reloadMarkers();
|
||||
// });
|
||||
// }
|
||||
|
||||
late Timer markerReloadingTimer2;
|
||||
late Timer markerReloadingTimer1;
|
||||
late int duration1;
|
||||
void startMarkerReloading() {
|
||||
// Schedule timer 1 to reload markers at a specific time
|
||||
DateTime scheduledTime1 = DateTime.now().add(const Duration(seconds: 30));
|
||||
markerReloadingTimer1 =
|
||||
Timer(scheduledTime1.difference(DateTime.now()), () {
|
||||
print('timer 1 ==============================');
|
||||
reloadMarkers();
|
||||
});
|
||||
|
||||
// Schedule timer 2 to reload markers at a specific time
|
||||
DateTime scheduledTime2 = DateTime.now().add(const Duration(seconds: 60));
|
||||
markerReloadingTimer2 =
|
||||
Timer(scheduledTime2.difference(DateTime.now()), () {
|
||||
print('timer 2 ==============================');
|
||||
reloadMarkers();
|
||||
});
|
||||
}
|
||||
|
||||
void reloadMarkers() async {
|
||||
await getCarsLocationByPassenger();
|
||||
// Clear existing markers
|
||||
markers.clear();
|
||||
getNearestDriverByPassengerLocation();
|
||||
// Add new markers
|
||||
// Example: Add a marker for each item in a list
|
||||
for (var item in carsLocationByPassenger) {
|
||||
final marker = Marker(
|
||||
infoWindow: InfoWindow(title: '${item.latitude} minutes'),
|
||||
markerId: MarkerId(duration1.toString()),
|
||||
position: LatLng(item.latitude, item.longitude),
|
||||
// Other properties for the marker, such as icon, info window, etc.
|
||||
);
|
||||
markers.add(marker);
|
||||
}
|
||||
|
||||
// Update the map with the new markers
|
||||
mapController?.animateCamera(CameraUpdate.newLatLng(
|
||||
LatLng(mylocation.latitude, mylocation.longitude)));
|
||||
}
|
||||
|
||||
String duratioByPassenger = '';
|
||||
void getNearestDriverByPassengerLocation() async {
|
||||
double nearestDistance = double.infinity;
|
||||
for (var i = 0; i < dataCarsLocationByPassenger['message'].length; i++) {
|
||||
var carLocation = dataCarsLocationByPassenger['message'][i];
|
||||
|
||||
// double distance1 = Geolocator.distanceBetween(
|
||||
// mylocation.latitude,
|
||||
// mylocation.longitude,
|
||||
// double.parse(carLocation['latitude']),
|
||||
// double.parse(carLocation['longitude']),
|
||||
// );
|
||||
// if (distance1 < nearestDistance) {
|
||||
// nearestDistance = distance1;
|
||||
// // nearestCarLocation = carLocation;
|
||||
// nearestCar = CarLocation(
|
||||
// distance: distance1,
|
||||
// id: carLocation['driver_id'],
|
||||
// latitude: double.parse(carLocation['latitude']),
|
||||
// longitude: double.parse(carLocation['longitude']),
|
||||
// );
|
||||
// }
|
||||
|
||||
update();
|
||||
// Make API request to get exact distance and duration
|
||||
String apiUrl =
|
||||
'${AppLink.googleMapsLink}distancematrix/json?destinations=${carLocation['latitude']},${carLocation['longitude']}&origins=${mylocation.latitude},${mylocation.longitude}&units=metric&key=${AppCredintials.mapAPIKEY}';
|
||||
var response = await CRUD().getGoogleApi(link: apiUrl, payload: {});
|
||||
if (response['status'] == "OK") {
|
||||
var data = response;
|
||||
// Extract distance and duration from the response and handle accordingly
|
||||
int distance1 = data['rows'][0]['elements'][0]['distance']['value'];
|
||||
duration1 = data['rows'][0]['elements'][0]['duration']['value'];
|
||||
duratioByPassenger = data['rows'][0]['elements'][0]['duration']['text'];
|
||||
|
||||
if (distance1 < nearestDistance) {
|
||||
nearestDistance = distance1.toDouble();
|
||||
|
||||
nearestCar = CarLocation(
|
||||
distance: distance1.toDouble(),
|
||||
duration: duration1.toDouble(),
|
||||
id: carLocation['driver_id'],
|
||||
latitude: double.parse(carLocation['latitude']),
|
||||
longitude: double.parse(carLocation['longitude']),
|
||||
);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle the distance and duration as needed
|
||||
else {
|
||||
print(
|
||||
'Failed to retrieve distance and duration: ${response['status']}');
|
||||
// Handle the failure case
|
||||
}
|
||||
}
|
||||
print(nearestCar!.distance);
|
||||
print(nearestCar!.duration);
|
||||
print(nearestCar!.latitude);
|
||||
print(nearestCar!.longitude);
|
||||
print(nearestCar!.id);
|
||||
}
|
||||
|
||||
late LatLngBounds boundsData;
|
||||
getMap(String origin, destination) async {
|
||||
var origin1 = fromString(origin);
|
||||
var destination1 = fromString(destination);
|
||||
@@ -322,13 +452,15 @@ class MapController extends GetxController {
|
||||
mydestination = destination1;
|
||||
mylocation = origin1;
|
||||
update();
|
||||
await getCarsLocationByPassenger();
|
||||
// print(carsLocationByPassenger);
|
||||
|
||||
var url =
|
||||
('${AppLink.googleMapsLink}directions/json?&language=en&avoid=tolls|ferries&destination=$destination&origin=$origin&key=${AppCredintials.mapAPIKEY}');
|
||||
|
||||
var response = await CRUD().getGoogleApi(link: url, payload: {});
|
||||
data = response['routes'][0]['legs'];
|
||||
|
||||
print(data);
|
||||
final points =
|
||||
decodePolyline(response["routes"][0]["overview_polyline"]["points"]);
|
||||
for (int i = 0; i < points.length; i++) {
|
||||
@@ -345,8 +477,7 @@ class MapController extends GetxController {
|
||||
LatLng(bounds['southwest']['lat'], bounds['southwest']['lng']);
|
||||
|
||||
// Create the LatLngBounds object
|
||||
LatLngBounds boundsData =
|
||||
LatLngBounds(northeast: northeast, southwest: southwest);
|
||||
boundsData = LatLngBounds(northeast: northeast, southwest: southwest);
|
||||
|
||||
// Calculate the zoom level based on the distance and screen size
|
||||
|
||||
@@ -376,10 +507,19 @@ class MapController extends GetxController {
|
||||
);
|
||||
|
||||
polylines.add(polyline);
|
||||
rideConfirm = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
showBottomSheet1() async {
|
||||
bottomSheet();
|
||||
isButtomSheetShown = true;
|
||||
heightButtomSheetShown = 250;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
double getDistanceFromText(String distanceText) {
|
||||
// Remove any non-digit characters from the distance text
|
||||
String distanceValue = distanceText.replaceAll(RegExp(r'[^0-9.]+'), '');
|
||||
@@ -406,6 +546,8 @@ class MapController extends GetxController {
|
||||
if (data.isNotEmpty) {
|
||||
String distanceText = await data[0]['distance']['text'];
|
||||
String durationText = await data[0]['duration']['text'];
|
||||
print(data[0]['duration']['text']);
|
||||
print('=================================');
|
||||
distance = getDistanceFromText(distanceText);
|
||||
duration = getDistanceFromText(durationText);
|
||||
durationToAdd = Duration(minutes: duration.toInt());
|
||||
@@ -562,14 +704,29 @@ class MapController extends GetxController {
|
||||
|
||||
@override
|
||||
void onInit() async {
|
||||
// getPolyLine();
|
||||
// getMap();
|
||||
FirebasMessagesController().requestPermission();
|
||||
await getLocation();
|
||||
await getCarsLocationByPassenger();
|
||||
getNearestDriverByPassengerLocation();
|
||||
addCustomPicker();
|
||||
addCustomCarIcon();
|
||||
startMarkerReloading();
|
||||
|
||||
super.onInit();
|
||||
}
|
||||
}
|
||||
|
||||
class CarLocation {
|
||||
final int id;
|
||||
final double latitude;
|
||||
final double longitude;
|
||||
double distance;
|
||||
double duration;
|
||||
|
||||
CarLocation({
|
||||
required this.id,
|
||||
required this.latitude,
|
||||
required this.longitude,
|
||||
this.distance = 10000,
|
||||
this.duration = 10000,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ class LocaleController extends GetxController {
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
FirebasMessagesController().requestPermission();
|
||||
String storedLang = box.read(BoxName.lang) ?? "";
|
||||
switch (storedLang) {
|
||||
case "ar":
|
||||
|
||||
@@ -37,12 +37,13 @@ void main() async {
|
||||
options: DefaultFirebaseOptions.currentPlatform,
|
||||
);
|
||||
}
|
||||
LocationPermissions().locationPermissions();
|
||||
|
||||
await FirebasMessagesController().requestFirebaseMessagingPermission();
|
||||
// await FirebasMessagesController().getNotificationSettings();
|
||||
FirebasMessagesController().getToken();
|
||||
await FirebasMessagesController().getTokens();
|
||||
LocationPermissions().locationPermissions();
|
||||
FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
|
||||
FirebasMessagesController().requestPermission();
|
||||
FirebasMessagesController().getNotificationSettings();
|
||||
|
||||
runApp(const MyApp());
|
||||
}
|
||||
@@ -57,7 +58,7 @@ class MyApp extends StatelessWidget {
|
||||
LocaleController controller = Get.put(LocaleController());
|
||||
|
||||
return GetMaterialApp(
|
||||
title: 'Ride',
|
||||
title: 'Sefer',
|
||||
translations: MyTranslation(),
|
||||
debugShowCheckedModeBanner: false,
|
||||
locale: controller.language,
|
||||
|
||||
@@ -49,8 +49,9 @@ class MapPage extends StatelessWidget {
|
||||
'${argument.latitude.toString()},${argument.longitude.toString()}');
|
||||
|
||||
Get.back();
|
||||
controller.changeButtomSheetShown();
|
||||
controller.bottomSheet();
|
||||
controller.showBottomSheet1();
|
||||
//
|
||||
},
|
||||
);
|
||||
},
|
||||
@@ -69,6 +70,7 @@ class MapPage extends StatelessWidget {
|
||||
for (var carLocation
|
||||
in controller.carsLocationByPassenger)
|
||||
Marker(
|
||||
// anchor: const Offset(4, 4),
|
||||
position: carLocation,
|
||||
icon: controller.carIcon,
|
||||
markerId: MarkerId(carLocation.toString())),
|
||||
@@ -149,7 +151,10 @@ class MapPage extends StatelessWidget {
|
||||
top: 80,
|
||||
left: 6,
|
||||
child: IconButton(
|
||||
onPressed: () => controller.changeMapType(),
|
||||
onPressed: () {
|
||||
controller.changeMapType();
|
||||
controller.reloadMarkers();
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.satellite_alt,
|
||||
size: 35,
|
||||
@@ -158,7 +163,7 @@ class MapPage extends StatelessWidget {
|
||||
),
|
||||
const PickerIconOnMap(),
|
||||
// PickerAnimtionContainerFormPlaces(),
|
||||
MainBottomMenuMap(),
|
||||
const MainBottomMenuMap(),
|
||||
const MapMenuWidget(),
|
||||
const MenuIconMapPageWidget(),
|
||||
buttomSheetMapPage(),
|
||||
@@ -178,8 +183,8 @@ class MapPage extends StatelessWidget {
|
||||
),
|
||||
))
|
||||
: const SizedBox()),
|
||||
CashConfirmPageShown(),
|
||||
PaymentMethodPage()
|
||||
const CashConfirmPageShown(),
|
||||
const PaymentMethodPage()
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -63,15 +63,16 @@ GetBuilder<MapController> formSearchPlaces() {
|
||||
title: 'Confirm'.tr,
|
||||
onPressed: () {
|
||||
controller.clearpolyline();
|
||||
controller.data = [];
|
||||
controller.getMap(
|
||||
'${controller.mylocation.latitude.toString()},${controller.mylocation.longitude.toString()}',
|
||||
"${res['geometry']['location']['lat']},${res['geometry']['location']['lng']}");
|
||||
controller.places = [];
|
||||
controller.placeController.clear();
|
||||
|
||||
controller.showBottomSheet1();
|
||||
Get.back();
|
||||
controller.changeButtomSheetShown();
|
||||
controller.bottomSheet();
|
||||
controller.showBottomSheet1();
|
||||
controller.changeMainBottomMenuMap();
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -61,31 +61,43 @@ class MainBottomMenuMap extends StatelessWidget {
|
||||
Radius.elliptical(15, 30),
|
||||
),
|
||||
),
|
||||
child: DefaultTextStyle(
|
||||
style: AppStyle.title,
|
||||
child: Center(
|
||||
child: AnimatedTextKit(
|
||||
animatedTexts: [
|
||||
ScaleAnimatedText(
|
||||
'${'Where to'.tr} ${box.read(BoxName.name)}'),
|
||||
WavyAnimatedText(
|
||||
'${'Where to'.tr} ${box.read(BoxName.name)}'),
|
||||
FlickerAnimatedText(
|
||||
'${'Where to'.tr} ${box.read(BoxName.name)}'),
|
||||
WavyAnimatedText(
|
||||
'${'Where to'.tr} ${box.read(BoxName.name)}'),
|
||||
],
|
||||
isRepeatingAnimation: true,
|
||||
onTap: () {
|
||||
print("Tap Event");
|
||||
controller.changeMainBottomMenuMap();
|
||||
},
|
||||
child: GestureDetector(
|
||||
onTap: () => controller.changeMainBottomMenuMap(),
|
||||
child: DefaultTextStyle(
|
||||
style: AppStyle.title,
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 30,
|
||||
child: AnimatedTextKit(
|
||||
animatedTexts: [
|
||||
ScaleAnimatedText(
|
||||
'${'Where to'.tr} ${box.read(BoxName.name)}'),
|
||||
// WavyAnimatedText(
|
||||
// '${'Where to'.tr} ${box.read(BoxName.name)}'),
|
||||
// FlickerAnimatedText(
|
||||
// '${'Where to'.tr} ${box.read(BoxName.name)}'),
|
||||
// WavyAnimatedText(
|
||||
// '${'Where to'.tr} ${box.read(BoxName.name)}'),
|
||||
],
|
||||
isRepeatingAnimation: true,
|
||||
onTap: () {
|
||||
print("Tap Event");
|
||||
},
|
||||
),
|
||||
),
|
||||
Text('Nearst Car for you about '.tr +
|
||||
controller.nearestCar!.duration
|
||||
.toString())
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)),
|
||||
),
|
||||
controller.isMainBottomMenuMap
|
||||
? FavioratePlacesDialogu()
|
||||
? const FavioratePlacesDialogu()
|
||||
: const SizedBox(),
|
||||
controller.isMainBottomMenuMap
|
||||
? const SizedBox()
|
||||
@@ -121,9 +133,9 @@ class FavioratePlacesDialogu extends StatelessWidget {
|
||||
ScaleAnimatedText(
|
||||
'Favorite Places'.tr,
|
||||
),
|
||||
TyperAnimatedText(
|
||||
'Favorite Places'.tr,
|
||||
),
|
||||
// TyperAnimatedText(
|
||||
// 'Favorite Places'.tr,
|
||||
// ),
|
||||
],
|
||||
isRepeatingAnimation: true,
|
||||
onTap: () async {
|
||||
@@ -165,10 +177,10 @@ class FavioratePlacesDialogu extends StatelessWidget {
|
||||
'${controller.mylocation.latitude},${controller.mylocation.longitude}',
|
||||
'${favoritePlaces[index]['latitude']},${favoritePlaces[index]['longitude']}',
|
||||
);
|
||||
controller.changePickerShown();
|
||||
controller.changeButtomSheetShown();
|
||||
controller.bottomSheet();
|
||||
// controller.changePickerShown();
|
||||
controller.showBottomSheet1();
|
||||
Get.back();
|
||||
controller.showBottomSheet1();
|
||||
},
|
||||
child: Text(
|
||||
favoritePlaces[index]['name'],
|
||||
|
||||
@@ -9,6 +9,7 @@ import firebase_core
|
||||
import firebase_messaging
|
||||
import flutter_local_notifications
|
||||
import flutter_secure_storage_macos
|
||||
import geolocator_apple
|
||||
import location
|
||||
import path_provider_foundation
|
||||
import sqflite
|
||||
@@ -19,6 +20,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
FLTFirebaseMessagingPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseMessagingPlugin"))
|
||||
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
|
||||
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
|
||||
GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin"))
|
||||
LocationPlugin.register(with: registry.registrar(forPlugin: "LocationPlugin"))
|
||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
|
||||
|
||||
56
pubspec.lock
@@ -296,6 +296,54 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
geolocator:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: geolocator
|
||||
sha256: "9d6eff112971b9f195271834b390fc0e1899a9a6c96225ead72efd5d4aaa80c7"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "10.0.0"
|
||||
geolocator_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: geolocator_android
|
||||
sha256: "835ff5b4888a2f8eba128996494faf9c5d422785322a81dc0565b99e0f6c379d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.2.2"
|
||||
geolocator_apple:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: geolocator_apple
|
||||
sha256: "36527c555f4c425f7d8fa8c7c07d67b78e3ff7590d40448051959e1860c1cfb4"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.7"
|
||||
geolocator_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: geolocator_platform_interface
|
||||
sha256: af4d69231452f9620718588f41acc4cb58312368716bfff2e92e770b46ce6386
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.0.7"
|
||||
geolocator_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: geolocator_web
|
||||
sha256: f68a122da48fcfff68bbc9846bb0b74ef651afe84a1b1f6ec20939de4d6860e1
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.6"
|
||||
geolocator_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: geolocator_windows
|
||||
sha256: "463045515b08bd83f73e014359c4ad063b902eb3899952cfb784497ae6c6583b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.2.0"
|
||||
get:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -805,6 +853,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.7"
|
||||
uuid:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: uuid
|
||||
sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.7"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -55,6 +55,7 @@ dependencies:
|
||||
animated_text_kit: ^4.2.2
|
||||
flutter_secure_storage: ^8.0.0
|
||||
credit_card_scanner: ^1.0.5
|
||||
geolocator: ^10.0.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <firebase_core/firebase_core_plugin_c_api.h>
|
||||
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
|
||||
#include <geolocator_windows/geolocator_windows.h>
|
||||
#include <url_launcher_windows/url_launcher_windows.h>
|
||||
|
||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||
@@ -15,6 +16,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||
registry->GetRegistrarForPlugin("FirebaseCorePluginCApi"));
|
||||
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
|
||||
GeolocatorWindowsRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("GeolocatorWindows"));
|
||||
UrlLauncherWindowsRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
firebase_core
|
||||
flutter_secure_storage_windows
|
||||
geolocator_windows
|
||||
url_launcher_windows
|
||||
)
|
||||
|
||||
|
||||
@@ -31,6 +31,11 @@ bool FlutterWindow::OnCreate() {
|
||||
this->Show();
|
||||
});
|
||||
|
||||
// Flutter can complete the first frame before the "show window" callback is
|
||||
// registered. The following call ensures a frame is pending to ensure the
|
||||
// window is shown. It is a no-op if the first frame hasn't completed yet.
|
||||
flutter_controller_->ForceRedraw();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
BIN
windows/runner/resources/playstore.png
Normal file
|
After Width: | Height: | Size: 32 KiB |