diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index c2775d1..e452311 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,28 +1,25 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + \ No newline at end of file diff --git a/lib/controller/firebase/firbase_messge.dart b/lib/controller/firebase/firbase_messge.dart index 3d5854f..2c97d72 100644 --- a/lib/controller/firebase/firbase_messge.dart +++ b/lib/controller/firebase/firbase_messge.dart @@ -8,6 +8,7 @@ import 'package:ride/constant/colors.dart'; import 'package:ride/constant/style.dart'; import 'package:ride/controller/functions/crud.dart'; import 'package:ride/controller/functions/launch.dart'; +import 'package:ride/controller/home/captin/map_dirction.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'; @@ -18,19 +19,20 @@ import '../../constant/links.dart'; import '../../main.dart'; import '../../views/orderCaptin/order_request_page.dart'; -class FirebasMessagesController extends GetxController { +class FirebaseMessagesController extends GetxController { final fcmToken = FirebaseMessaging.instance; List tokens = []; List dataTokens = []; late String driverID; + late String driverToken; NotificationSettings? notificationSettings; @override void onInit() async { super.onInit(); // getNotificationSettings(); - getToken(); - await getTokens(); + // getToken(); + // await getTokens(); } Future getNotificationSettings() async { @@ -106,6 +108,9 @@ class FirebasMessagesController extends GetxController { print(myListString); print('9999999999999myListString999999999999999'); var myList = jsonDecode(myListString) as List; + driverToken = myList[14].toString(); + update(); + print('driverToken==============' + driverToken.toString()); Get.to(() => OrderRequestPage(), arguments: { 'myListString': myListString, 'DriverList': myList, @@ -117,6 +122,7 @@ class FirebasMessagesController extends GetxController { print('9999999999999my Apply Ride 999999999999999'); var myList = jsonDecode(passengerList) as List; driverID = myList[2].toString(); + Get.snackbar( 'Captin Applied the Ride for You'.tr, 'message', @@ -178,12 +184,15 @@ class FirebasMessagesController extends GetxController { ); } else if (message.notification!.title!.contains('Promo')) { Get.to(const PromosPassengerPage()); - } else if (message.notification!.title == ('Ride Begin')) { - Get.snackbar( - 'Trip Begin'.tr, - 'by Passenger'.tr, - backgroundColor: AppColor.yellowColor, + } else if (message.notification!.title!.contains('BeginTrip')) { + // MapDirection mapDirection = Get.find(); + // mapDirection.clearPolyline(); + print('jjjjjjjjjjjjjjjjjjjjjjjjjjj'); + Get.defaultDialog( + title: 'The Ride is Begin'.tr, + backgroundColor: AppColor.greenColor, ); + MapDirection().clearPolyline(); } } }); @@ -470,27 +479,39 @@ class FirebasMessagesController extends GetxController { } } - void sendNotificationToDriverId(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' - }, - 'data': {}, - 'priority': 'high', - 'to': token, - })) - .whenComplete(() {}) - .catchError((e) { + void sendNotificationToDriverId( + String title, String body, String token) async { + try { + final response = await 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' + }, + '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'); - }); + } } void sendNotificationToDriverMAP( diff --git a/lib/controller/functions/crud.dart b/lib/controller/functions/crud.dart index 7bf73f2..0bade75 100644 --- a/lib/controller/functions/crud.dart +++ b/lib/controller/functions/crud.dart @@ -49,8 +49,8 @@ class CRUD { 'Basic ${base64Encode(utf8.encode(AppCredintials.basicAuthCredentials))}', }, ); - print(response.request); - print(payload); + // print(response.request); + // print(payload); var jsonData = jsonDecode(response.body); if (response.statusCode == 200) { diff --git a/lib/controller/functions/location_controller.dart b/lib/controller/functions/location_controller.dart index 015ad26..0ff29dc 100644 --- a/lib/controller/functions/location_controller.dart +++ b/lib/controller/functions/location_controller.dart @@ -77,10 +77,10 @@ class LocationController extends GetxController { : null)!; // Print location details - print('Accuracy: ${_locationData.accuracy}'); - print('Latitude: ${_locationData.latitude}'); - print('Longitude: ${_locationData.longitude}'); - print('Time: ${_locationData.time}'); + // print('Accuracy: ${_locationData.accuracy}'); + // print('Latitude: ${_locationData.latitude}'); + // print('Longitude: ${_locationData.longitude}'); + // print('Time: ${_locationData.time}'); isLoading = false; update(); } diff --git a/lib/controller/home/captin/map_dirction.dart b/lib/controller/home/captin/map_dirction.dart index 300e62e..df80d64 100644 --- a/lib/controller/home/captin/map_dirction.dart +++ b/lib/controller/home/captin/map_dirction.dart @@ -1,21 +1,69 @@ +import 'dart:async'; + +import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_polyline_algorithm/google_polyline_algorithm.dart'; import 'package:ride/constant/colors.dart'; +import 'package:ride/controller/functions/location_controller.dart'; import '../../../constant/credential.dart'; import '../../../constant/links.dart'; import '../../functions/crud.dart'; -class MapDirction extends GetxController { +class MapDirection extends GetxController { bool isLoading = true; List data = []; - LatLngBounds? boundsdata; - + LatLngBounds? boundsData; + BitmapDescriptor carIcon = BitmapDescriptor.defaultMarker; final List polylineCoordinates = []; List polyLines = []; + Set markers = {}; - getMap(LatLng origin, destination) async { + void clearPolyline() { + polyLines = []; + polylineCoordinates.clear(); + update(); + } + + void updateMarker() { + // Remove the existing marker with the ID `MyLocation`. + markers.remove(MarkerId('MyLocation'.tr)); + + // Add a new marker with the ID `MyLocation` at the current location of the user. + LocationController locationController = Get.find(); + markers.add(Marker( + markerId: MarkerId('MyLocation'.tr), + position: locationController.myLocation, + draggable: true, + icon: carIcon, + // infoWindow: const InfoWindow( + // title: 'Time', + // ), + )); + + // Update the `markers` set and call the `update()` method on the controller to notify the view that the marker position has changed. + update(); + + // Reload the marker after 3 seconds. + Future.delayed(const Duration(seconds: 3), () { + updateMarker(); + }); + } + + void addCustomCarIcon() { + ImageConfiguration config = ImageConfiguration( + size: Size(Get.width * .6, Get.height * .6), + // scale: 1.0, + ); + BitmapDescriptor.fromAssetImage(config, 'assets/images/car.png') + .then((value) { + carIcon = value; + update(); + }); + } + + getMap(String origin, destination) async { isLoading = false; update(); @@ -34,7 +82,16 @@ class MapDirction extends GetxController { polylineCoordinates.add(LatLng(lat, lng)); } if (polyLines.isNotEmpty) { - // clearPolyline(); + clearPolyline(); + var polyline = Polyline( + polylineId: PolylineId(response["routes"][0]["summary"]), + points: polylineCoordinates, + width: 10, + color: AppColor.blueColor, + ); + polyLines.add(polyline); + // rideConfirm = false; + update(); } else { var polyline = Polyline( polylineId: PolylineId(response["routes"][0]["summary"]), @@ -43,7 +100,7 @@ class MapDirction extends GetxController { color: AppColor.blueColor, ); - // polyLines.add(polyline); + polyLines.add(polyline); // rideConfirm = false; update(); } @@ -51,6 +108,15 @@ class MapDirction extends GetxController { @override void onInit() { + // Get the passenger location from the arguments. + String passengerLocation = Get.arguments['passengerLocation']; + String lat = Get.find().myLocation.latitude.toString(); + String lng = Get.find().myLocation.longitude.toString(); + String origin = '$lat,$lng'; + // Set the origin and destination coordinates for the Google Maps directions request. + getMap(origin, passengerLocation); + addCustomCarIcon(); + updateMarker(); super.onInit(); } } diff --git a/lib/controller/home/map_page_controller.dart b/lib/controller/home/map_page_controller.dart index 75378e5..f6660d6 100644 --- a/lib/controller/home/map_page_controller.dart +++ b/lib/controller/home/map_page_controller.dart @@ -168,6 +168,7 @@ class MapController extends GetxController { } var rideId; + late String driverToken; int carsOrder = 0; changeConfirmRide() async { PaymentController paymentController = Get.find(); @@ -175,6 +176,8 @@ class MapController extends GetxController { shouldFetch = true; isBottomSheetShown = false; timeToPassengerFromDriverAfterApplied = 60; + driverToken = + dataCarsLocationByPassenger['message'][carsOrder]['token'].toString(); update(); // print('rideConfirm= $rideConfirm'); @@ -189,7 +192,8 @@ class MapController extends GetxController { "endtime": durationToAdd.toString(), "price": totalPassenger.toString(), "passenger_id": box.read(BoxName.pasengerID).toString(), - "driver_id": dataCarsLocationByPassenger['message'][0]['id'].toString(), + "driver_id": + dataCarsLocationByPassenger['message'][carsOrder]['id'].toString(), "status": "waiting", "price_for_driver": totalDriver.toString(), "price_for_passenger": totalME.toString(), @@ -214,9 +218,10 @@ class MapController extends GetxController { box.read(BoxName.phone).toString(), durationByPassenger.toString(), distanceByPassenger.toString(), - paymentController.isWalletChecked.toString() + paymentController.isWalletChecked.toString(), + dataCarsLocationByPassenger['message'][carsOrder]['token'].toString(), ]; - FirebasMessagesController().sendNotificationToDriverMAP( + FirebaseMessagesController().sendNotificationToDriverMAP( 'Order', jsonDecode(value)['message'].toString(), dataCarsLocationByPassenger['message'][carsOrder]['token'].toString(), @@ -410,6 +415,7 @@ class MapController extends GetxController { changeCancelRidePageShow(); rideConfirm = false; shouldFetch = false; + timeToPassengerFromDriverAfterApplied = 0; update(); } else { clearPlaces(); @@ -417,12 +423,13 @@ class MapController extends GetxController { data = []; rideConfirm = false; shouldFetch = false; + timeToPassengerFromDriverAfterApplied = 0; changeCancelRidePageShow(); remainingTime = 25; update(); await CRUD().post(link: AppLink.addCancelRideFromPassenger, payload: { - "driverID": FirebasMessagesController() + "driverID": FirebaseMessagesController() .driverID .toString(), // Convert to String "passengerID": diff --git a/lib/main.dart b/lib/main.dart index 1f47653..0739d32 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -40,9 +40,9 @@ void main() async { ); } - await FirebasMessagesController().requestFirebaseMessagingPermission(); + await FirebaseMessagesController().requestFirebaseMessagingPermission(); // await FirebasMessagesController().getNotificationSettings(); - await FirebasMessagesController().getToken(); + await FirebaseMessagesController().getToken(); // await FirebasMessagesController().getTokens(); LocationPermissions().locationPermissions(); FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler); diff --git a/lib/views/home/map_widget.dart/timer_to_passenger_from_driver.dart b/lib/views/home/map_widget.dart/timer_to_passenger_from_driver.dart index e630f3b..a2e0159 100644 --- a/lib/views/home/map_widget.dart/timer_to_passenger_from_driver.dart +++ b/lib/views/home/map_widget.dart/timer_to_passenger_from_driver.dart @@ -67,37 +67,27 @@ class TimerToPassengerFromDriver extends StatelessWidget { ? MyElevatedButton( title: 'If you in Car Now. Press Start The Ride', onPressed: () async { - MapController mapController = - Get.find(); - final firebasMessagesController = - Get.put(FirebasMessagesController()); //todo start the trip and rest all counter ,start new counter of the trip time + await CRUD() .post(link: AppLink.updateRides, payload: { - 'id': mapController.rideId, + 'id': controller.rideId, 'rideTimeStart': DateTime.now().toString(), 'status': 'Applied' }); - mapController.driverArrivePassenger(); + controller.driverArrivePassenger(); // Send notification to driver to alert him that trip is begin - firebasMessagesController + FirebaseMessagesController() .sendNotificationToDriverId( - 'Ride Begin', + 'BeginTrip', box.read(BoxName.name).toString(), - mapController - .dataCarsLocationByPassenger['message'][0] - ['token'] - .toString(), - ); - print(mapController - .dataCarsLocationByPassenger['message'][0] - ['token'] - .toString()); - Get.snackbar( - 'The Ride is Begin'.tr, - '', - backgroundColor: AppColor.greenColor, + controller.driverToken.toString(), ); + print(controller.driverToken.toString()); + // Get.defaultDialog( + // title: 'The Ride is Begin'.tr, + // backgroundColor: AppColor.greenColor, + // ); }) : const SizedBox() ], diff --git a/lib/views/orderCaptin/order_request_page.dart b/lib/views/orderCaptin/order_request_page.dart index 4daa550..6bd4df9 100644 --- a/lib/views/orderCaptin/order_request_page.dart +++ b/lib/views/orderCaptin/order_request_page.dart @@ -178,7 +178,7 @@ class OrderRequestPage extends StatelessWidget { box.read(BoxName.tokenDriver).toString(), ]; // print(bodyToPassenger); - FirebasMessagesController() + FirebaseMessagesController() .sendNotificanToPassengerToken( 'Apply Ride', arguments['DriverList'][9].toString(), @@ -187,7 +187,9 @@ class OrderRequestPage extends StatelessWidget { bodyToPassenger, ); Get.back(); - Get.to(() => PassengerLocationDirection()); + Get.to(() => PassengerLocationDirection(), arguments: { + 'passengerLocation': myList[0].toString(), + }); }, ), GetBuilder( @@ -222,7 +224,7 @@ class OrderRequestPage extends StatelessWidget { orderRequestController.refuseOrder( myList[6].toString(), body.toString()); - FirebasMessagesController() + FirebaseMessagesController() .sendNotificanToPassengerToken( 'Refused Ride', arguments['DriverList'][9].toString(), diff --git a/lib/views/orderCaptin/passenger_location_dirction.dart b/lib/views/orderCaptin/passenger_location_dirction.dart index 616b8ec..d884b31 100644 --- a/lib/views/orderCaptin/passenger_location_dirction.dart +++ b/lib/views/orderCaptin/passenger_location_dirction.dart @@ -4,30 +4,65 @@ import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:ride/controller/home/captin/map_dirction.dart'; import 'package:ride/views/widgets/my_scafold.dart'; +import '../../constant/colors.dart'; import '../../controller/functions/location_controller.dart'; -import '../widgets/mycircular.dart'; +import '../home/map_widget.dart/passenger_info_window.dart'; +import '../home/map_widget.dart/timer_to_passenger_from_driver.dart'; class PassengerLocationDirection extends StatelessWidget { PassengerLocationDirection({super.key}); - // final LocationController locationController = Get.put(LocationController()); - // final MapDirection mapDirection = Get.find(); + final LocationController locationController = Get.put(LocationController()); @override Widget build(BuildContext context) { - Get.put(LocationController()); + Get.put(MapDirection()); + // mapDirection.getMap();//todo get this argument return MyScafolld( title: 'Map'.tr, body: [ Padding( padding: const EdgeInsets.all(8.0), - child: GetBuilder( - builder: (controller) => GoogleMap( - initialCameraPosition: CameraPosition( - target: controller.myLocation, - zoom: 15, - ), - )), - ) + child: GetBuilder( + builder: (controller) => GoogleMap( + initialCameraPosition: CameraPosition( + target: locationController.myLocation, + zoom: 15, + ), + polylines: { + Polyline( + zIndex: 2, + consumeTapEvents: true, + geodesic: true, + endCap: Cap.buttCap, + startCap: Cap.buttCap, + visible: true, + polylineId: const PolylineId('route'), + points: controller.polylineCoordinates, + color: AppColor.greenColor, + width: 5, + ), + }, + markers: { + Marker( + markerId: MarkerId('MyLocation'.tr), + position: locationController.myLocation, + draggable: true, + icon: controller.carIcon, + infoWindow: const InfoWindow( + title: 'Time', + // snippet: controller.durationFromDriverToPassenger + // .toString(), + ), + ), + }, + onCameraMove: (cameraPosition) { + controller.updateMarker(); + }, + ), + ), + ), + // const TimerToPassengerFromDriver(), + const PassengerInfoWindow() ], isleading: true); } diff --git a/pubspec.yaml b/pubspec.yaml index 4e49a17..6c3af88 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -67,6 +67,7 @@ flutter: - assets/images/ - assets/lottie/ - assets/fonts/ + - shorebird.yaml fonts: - family: digital-counter-7 diff --git a/shorebird.yaml b/shorebird.yaml new file mode 100644 index 0000000..aaa3af7 --- /dev/null +++ b/shorebird.yaml @@ -0,0 +1,14 @@ +# This file is used to configure the Shorebird updater used by your app. +# Learn more at https://docs.shorebird.dev +# This file should be checked into version control. + +# This is the unique identifier assigned to your app. +# Your app_id is not a secret and is just used to identify your app +# when requesting patches from Shorebird's servers. +app_id: 8a571d7f-dfbf-4a65-be62-17eed08cbd5c + +# auto_update controls if Shorebird should automatically update in the background on launch. +# If auto_update: false, you will need to use package:shorebird_code_push to trigger updates. +# https://pub.dev/packages/shorebird_code_push +# Uncomment the following line to disable automatic updates. +# auto_update: false