diff --git a/android/app/src/main/res/drawable/app_icon.png b/android/app/src/main/res/drawable/app_icon.png index f7af634..7567e84 100644 Binary files a/android/app/src/main/res/drawable/app_icon.png and b/android/app/src/main/res/drawable/app_icon.png differ diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png index 4cdf4ba..5a742fc 100644 Binary files a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png index d727995..5f6b009 100644 Binary files a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png index a8e695c..154eacd 100644 Binary files a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png index dae61b3..dc8ba36 100644 Binary files a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png index fcab8e5..50ec270 100644 Binary files a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/assets/images/logo.png b/assets/images/logo.png index 776785b..7567e84 100644 Binary files a/assets/images/logo.png and b/assets/images/logo.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/100.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/100.png index 06a5ca4..75be1fc 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/100.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/100.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/1024.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/1024.png index 776785b..70f909f 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/1024.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/1024.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/114.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/114.png index 9d849c2..f632181 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/114.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/114.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/120.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/120.png index fa21b1d..effbbf1 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/120.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/120.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/128.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/128.png index 723651e..4abde65 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/128.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/128.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/144.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/144.png index dae61b3..dc8ba36 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/144.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/144.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/152.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/152.png index d8b1a7f..888fbae 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/152.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/152.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/16.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/16.png index f187210..7cbcb90 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/16.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/16.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/167.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/167.png index 9f9ea91..6c87ea7 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/167.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/167.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/180.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/180.png index a4cb198..ad52c72 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/180.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/180.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/20.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/20.png index 9cd0b7a..af1570a 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/20.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/20.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/256.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/256.png index c0ae1fb..b34e5c3 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/256.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/256.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/29.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/29.png index a4c5844..2a4539e 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/29.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/29.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/32.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/32.png index 5f8c2f2..468a2ed 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/32.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/32.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/40.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/40.png index b0270d4..4dc5b2f 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/40.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/40.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/50.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/50.png index d54573f..8e917d6 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/50.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/50.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/512.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/512.png index f7af634..7567e84 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/512.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/512.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/57.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/57.png index 88246f8..4b6ced6 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/57.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/57.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/58.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/58.png index 579ecfb..e4d6302 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/58.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/58.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/60.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/60.png index 6375658..ac9215d 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/60.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/60.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/64.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/64.png index c05e1b0..6d52ff5 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/64.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/64.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/72.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/72.png index 4cdf4ba..5a742fc 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/72.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/72.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/76.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/76.png index f98f82d..a093ce2 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/76.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/76.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/80.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/80.png index e1bb646..59aa302 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/80.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/80.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/87.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/87.png index f94f8e5..58e6d05 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/87.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/87.png differ diff --git a/lib/controller/auth/login_controller.dart b/lib/controller/auth/login_controller.dart index c147549..ea2f773 100644 --- a/lib/controller/auth/login_controller.dart +++ b/lib/controller/auth/login_controller.dart @@ -108,7 +108,5 @@ class LoginController extends GetxController { @override void onInit() { super.onInit(); - FirebasMessagesController().requestPermission(); - // goToMapPage(); } } diff --git a/lib/controller/firebase/firbase_messge.dart b/lib/controller/firebase/firbase_messge.dart index c5ae855..2331612 100644 --- a/lib/controller/firebase/firbase_messge.dart +++ b/lib/controller/firebase/firbase_messge.dart @@ -22,52 +22,30 @@ class FirebasMessagesController extends GetxController { super.onInit(); // getNotificationSettings(); getToken(); - getTokens(); + await getTokens(); } Future 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 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: { - 'Content-Type': 'application/json', - 'Authorization': 'key=${AppCredintials.serverAPI}' - }, - body: jsonEncode({ - 'notification': { - 'title': title, - 'body': body, - 'sound': 'true' - }, - 'priority': 'high', - 'data': { - '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: { + // 'Content-Type': 'application/json', + // 'Authorization': 'key=${AppCredintials.serverAPI}' + // }, + // body: jsonEncode({ + // 'notification': { + // 'title': title, + // 'body': body, + // 'sound': 'true' + // }, + // 'priority': 'high', + // 'data': { + // '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: { - 'Content-Type': 'application/json', - 'Authorization': 'key=${AppCredintials.serverAPI}' - }, - body: jsonEncode({ - 'notification': { - 'title': title, - 'body': body, - 'sound': 'true' - }, - 'priority': 'high', - 'data': { - '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: { + // 'Content-Type': 'application/json', + // 'Authorization': 'key=${AppCredintials.serverAPI}' + // }, + // body: jsonEncode({ + // 'notification': { + // 'title': title, + // 'body': body, + // 'sound': 'true' + // }, + // 'priority': 'high', + // 'data': { + // 'click_action': 'FLUTTER_NOTIFICATION_CLICK', + // 'id': '1', + // 'status': 'done' + // }, + // 'to': token, + // })) + // .whenComplete(() {}) + // .catchError((e) { + // print('sendNotification() error: $e'); + // }); + // } } diff --git a/lib/controller/functions/crud.dart b/lib/controller/functions/crud.dart index 1ea5f2e..a348375 100644 --- a/lib/controller/functions/crud.dart +++ b/lib/controller/functions/crud.dart @@ -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']; diff --git a/lib/controller/home/map_page_controller.dart b/lib/controller/home/map_page_controller.dart index 3417d57..dc42bf5 100644 --- a/lib/controller/home/map_page_controller.dart +++ b/lib/controller/home/map_page_controller.dart @@ -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 polylineCoordinates = []; - final List carsLocationByPassenger = []; + List 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 carLocations = []; - + var dataCarsLocationByPassenger; + CarLocation? nearestCar; + late Timer markerReloadingTimer; // final mainBottomMenuMap = GlobalKey(); 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, + }); +} diff --git a/lib/controller/local/local_controller.dart b/lib/controller/local/local_controller.dart index 118d48c..1fff609 100644 --- a/lib/controller/local/local_controller.dart +++ b/lib/controller/local/local_controller.dart @@ -40,7 +40,6 @@ class LocaleController extends GetxController { @override void onInit() { - FirebasMessagesController().requestPermission(); String storedLang = box.read(BoxName.lang) ?? ""; switch (storedLang) { case "ar": diff --git a/lib/main.dart b/lib/main.dart index 0823ce9..15e6d72 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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, diff --git a/lib/views/home/map_page.dart b/lib/views/home/map_page.dart index 7556273..05808d2 100644 --- a/lib/views/home/map_page.dart +++ b/lib/views/home/map_page.dart @@ -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() ], ), ); diff --git a/lib/views/home/map_widget.dart/form_search_places.dart b/lib/views/home/map_widget.dart/form_search_places.dart index 99d360d..53aeea7 100644 --- a/lib/views/home/map_widget.dart/form_search_places.dart +++ b/lib/views/home/map_widget.dart/form_search_places.dart @@ -63,15 +63,16 @@ GetBuilder 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(); }), ); diff --git a/lib/views/home/map_widget.dart/main_bottom_Menu_map.dart b/lib/views/home/map_widget.dart/main_bottom_Menu_map.dart index f29e52a..08d5b4b 100644 --- a/lib/views/home/map_widget.dart/main_bottom_Menu_map.dart +++ b/lib/views/home/map_widget.dart/main_bottom_Menu_map.dart @@ -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'], diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 881df5d..52a6b45 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -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")) diff --git a/pubspec.lock b/pubspec.lock index f212ac9..4b207fb 100644 --- a/pubspec.lock +++ b/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: diff --git a/pubspec.yaml b/pubspec.yaml index 01b65fa..cb36ba1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 0e0afee..fc8aa54 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -8,6 +8,7 @@ #include #include +#include #include 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")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 9efea82..3d0634f 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -5,6 +5,7 @@ list(APPEND FLUTTER_PLUGIN_LIST firebase_core flutter_secure_storage_windows + geolocator_windows url_launcher_windows ) diff --git a/windows/runner/flutter_window.cpp b/windows/runner/flutter_window.cpp index b25e363..955ee30 100644 --- a/windows/runner/flutter_window.cpp +++ b/windows/runner/flutter_window.cpp @@ -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; } diff --git a/windows/runner/resources/playstore.png b/windows/runner/resources/playstore.png new file mode 100644 index 0000000..7567e84 Binary files /dev/null and b/windows/runner/resources/playstore.png differ