From 9a58d59f4e4a3b1f5ef3a2ceb2c4590917570842 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Thu, 25 Jan 2024 02:10:41 +0300 Subject: [PATCH] 1/25/1 --- lib/controller/firebase/firbase_messge.dart | 8 --- lib/controller/functions/launch.dart | 66 ++++++++++++++----- .../home/map_passenger_controller.dart | 57 +++++++++++----- lib/controller/themes/themes.dart | 24 +++++++ .../Captin/history/history_details_page.dart | 2 +- .../orderCaptin/order_request_page.dart | 2 +- .../buttom_sheet_map_show.dart | 2 +- .../map_widget.dart/ride_begin_passenger.dart | 37 +++++++++++ lib/views/home/profile/order_history.dart | 2 +- 9 files changed, 153 insertions(+), 47 deletions(-) diff --git a/lib/controller/firebase/firbase_messge.dart b/lib/controller/firebase/firbase_messge.dart index affec11..a20d9d7 100644 --- a/lib/controller/firebase/firbase_messge.dart +++ b/lib/controller/firebase/firbase_messge.dart @@ -271,11 +271,7 @@ class FirebaseMessagesController extends GetxController { 'notification': { 'title': title, 'body': body, -<<<<<<< HEAD 'sound': 'tone2.wav' -======= - 'sound': 'tone2.wav' ->>>>>>> 158d5dfb356420937651bcd4d22a779f03a12e07 }, 'data': { 'passengerList': map, @@ -312,11 +308,7 @@ class FirebaseMessagesController extends GetxController { 'notification': { 'title': title, 'body': body, -<<<<<<< HEAD 'sound': 'tone2.wav' -======= - 'sound': 'tone2.wav' ->>>>>>> 158d5dfb356420937651bcd4d22a779f03a12e07 }, 'data': { 'click_action': 'FLUTTER_NOTIFICATION_CLICK', diff --git a/lib/controller/functions/launch.dart b/lib/controller/functions/launch.dart index 6ec3056..c4a5668 100644 --- a/lib/controller/functions/launch.dart +++ b/lib/controller/functions/launch.dart @@ -1,6 +1,7 @@ import 'package:url_launcher/url_launcher.dart'; +import 'dart:io'; -void launchUrl1(String url) async { +void showInBrowser(String url) async { if (await canLaunchUrl(Uri.parse(url))) { launchUrl(Uri.parse(url)); } else { @@ -12,22 +13,53 @@ void launchCommunication( String method, String contactInfo, String message) async { String url; - switch (method) { - case 'phone': - url = 'tel:$contactInfo'; - break; - case 'sms': - url = 'sms:$contactInfo?body=$message'; - break; - case 'whatsapp': - url = 'whatsapp://send?phone=$contactInfo&text=$message'; - break; - case 'email': - url = 'mailto:$contactInfo?subject=Subject&body=$message'; - break; - default: - print('Invalid communication method'); - return; + if (Platform.isIOS) { + switch (method) { + case 'phone': + url = 'tel:$contactInfo'; + break; + + case 'sms': + url = 'sms:$contactInfo?body=$message'; + break; + + case 'whatsapp': + url = 'https://api.whatsapp.com/send?phone=$contactInfo&text=$message'; + break; + + case 'email': + url = 'mailto:$contactInfo?subject=Subject&body=$message'; + break; + + default: + print('Method not supported on iOS'); + return; + } + } else if (Platform.isAndroid) { + switch (method) { + case 'phone': + url = 'tel:$contactInfo'; + break; + + case 'sms': + url = 'sms:$contactInfo?body=$message'; + break; + + case 'whatsapp': + url = 'whatsapp://send?phone=$contactInfo&text=$message'; + break; + + case 'email': + url = 'mailto:$contactInfo?subject=Subject&body=$message'; + break; + + default: + print('Method not supported on Android'); + return; + } + } else { + print('Platform not supported'); + return; } if (await canLaunchUrl(Uri.parse(url))) { diff --git a/lib/controller/home/map_passenger_controller.dart b/lib/controller/home/map_passenger_controller.dart index e1902dd..43aaf45 100644 --- a/lib/controller/home/map_passenger_controller.dart +++ b/lib/controller/home/map_passenger_controller.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'dart:convert'; +import 'dart:io'; import 'dart:math' show cos; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -12,6 +13,7 @@ import 'package:ride/constant/style.dart'; import 'package:ride/controller/home/points_for_rider_controller.dart'; import 'package:ride/views/home/map_page_passenger.dart'; import 'package:ride/views/home/map_widget.dart/form_serch_multiy_point.dart'; +import 'package:url_launcher/url_launcher.dart'; import '../../constant/api_key.dart'; import '../../constant/box_name.dart'; import '../../constant/info.dart'; @@ -436,6 +438,25 @@ class MapPassengerController extends GetxController { } } + // Create a StreamController to manage the timer values + final timerController = StreamController(); + +// Start the timer when the ride begins + void beginRideTimer() { + // Set up the timer to run every second + Timer.periodic(const Duration(seconds: 1), (timer) { + // Update the timer value and notify listeners + timerController.add(timer.tick); + update(); + }); + } + +// Stop the timer when the ride ends + void stopRideTimer() { + timerController.close(); + update(); + } + void rideIsBeginPassengerTimer() async { for (int i = 0; i <= durationToRide; i++) { await Future.delayed(const Duration(seconds: 1)); @@ -962,12 +983,12 @@ class MapPassengerController extends GetxController { // int waypointsLength = Get.find().wayPoints.length; print('isWayPointStopsSheet $wayPointIndex'); - if (wayPointIndex > 1) { + if (wayPointIndex > -1) { isWayPointStopsSheet = true; isWayPointStopsSheetUtilGetMap = true; } isWayPointStopsSheet = !isWayPointStopsSheet; - wayPointSheetHeight = isWayPointStopsSheet == false ? 0 : Get.height * .45; + wayPointSheetHeight = isWayPointStopsSheet ? Get.height * .45 : 0; // if (heightMenuBool == true) { // getDrawerMenu(); // } @@ -1416,26 +1437,26 @@ class MapPassengerController extends GetxController { // Calculate the zoom level based on the distance and screen size - double distanceOfDestnation = - getDistanceFromText(data[0]['distance']['text']); - + // getDistanceFromText(data[0]['distance']['text']); + double distanceOfTrip = (data[0]['distance']['value']) / 1000; + print('distance is $distanceOfTrip'); // Animate the camera to the adjusted bounds - if (distanceOfDestnation <= 5) { + if (distanceOfTrip <= 5) { mapController! .animateCamera(CameraUpdate.newLatLngZoom(newStartPointLocation, 14)); - } else if (distanceOfDestnation > 5 && distanceOfDestnation <= 8) { + } else if (distanceOfTrip > 5 && distanceOfTrip <= 8) { mapController! - .animateCamera(CameraUpdate.newLatLngZoom(newStartPointLocation, 13)); - } else if (distanceOfDestnation > 8 && distanceOfDestnation < 16) { + .animateCamera(CameraUpdate.newLatLngZoom(newStartPointLocation, 16)); + } else if (distanceOfTrip > 8 && distanceOfTrip < 16) { mapController! .animateCamera(CameraUpdate.newLatLngZoom(newStartPointLocation, 12)); - } else if (distanceOfDestnation >= 16 && distanceOfDestnation < 30) { + } else if (distanceOfTrip >= 16 && distanceOfTrip < 30) { mapController! .animateCamera(CameraUpdate.newLatLngZoom(newStartPointLocation, 11)); - } else if (distanceOfDestnation >= 30 && distanceOfDestnation < 100) { + } else if (distanceOfTrip >= 30 && distanceOfTrip < 100) { mapController! .animateCamera(CameraUpdate.newLatLngZoom(newStartPointLocation, 10)); - } else if (distanceOfDestnation >= 100) { + } else if (distanceOfTrip >= 100) { mapController! .animateCamera(CameraUpdate.newLatLngZoom(newStartPointLocation, 7)); } @@ -1476,9 +1497,9 @@ class MapPassengerController extends GetxController { durationToRide = durationToRide + durationToRide0; print('durationToRide is ${data[0]['duration']['value']}'); print('totalStepDurations is $durationToRide'); - double distanceToRide0 = (data[0]['distance']['value']) / 1000; - distanceOfDestnation = distanceOfDestnation + distanceToRide0; - print('distanceToRide is $distanceToRide0'); + print('distanceToRide is ${(data[0]['distance']['value']) / 1000}'); + distance = distanceOfDestnation + (data[0]['distance']['value']) / 1000; + print('totalStepdistance is $distanceOfDestnation'); update(); final points = @@ -1596,11 +1617,11 @@ class MapPassengerController extends GetxController { Future bottomSheet() async { if (data.isNotEmpty) { String distanceText = await data[0]['distance']['text']; - String durationText = await data[0]['duration']['text']; + // String durationText = await data[0]['duration']['text']; print(data[0]['duration']['text']); print('================================='); - distance = getDistanceFromText(distanceText); - duration = getDistanceFromText(durationText); + // distance = getDistanceFromText(distanceText); + // duration = getDistanceFromText(durationText); durationToAdd = Duration(seconds: durationToRide); print('durationToRide----- $durationToRide'); hours = durationToAdd.inHours; diff --git a/lib/controller/themes/themes.dart b/lib/controller/themes/themes.dart index fee1ca9..a6ac191 100644 --- a/lib/controller/themes/themes.dart +++ b/lib/controller/themes/themes.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:ride/constant/style.dart'; import '../../constant/colors.dart'; @@ -25,6 +26,29 @@ ThemeData themeEnglish = ThemeData( bodyMedium: TextStyle(height: 2, color: AppColor.accentColor, fontSize: 14)), primarySwatch: Colors.blue, + dialogTheme: DialogTheme( + backgroundColor: AppColor.secondaryColor, + contentTextStyle: AppStyle.title, + titleTextStyle: AppStyle.title, + ), + appBarTheme: AppBarTheme( + elevation: 0, + color: AppColor.secondaryColor, + centerTitle: true, + iconTheme: const IconThemeData( + color: AppColor.primaryColor, + ), + toolbarTextStyle: TextTheme( + titleSmall: AppStyle.subtitle, + headlineSmall: AppStyle.title, + titleLarge: AppStyle.headTitle2) + .bodyMedium, + titleTextStyle: TextTheme( + titleSmall: AppStyle.subtitle, + headlineSmall: AppStyle.title, + titleLarge: AppStyle.headTitle2) + .titleLarge, + ), ); ThemeData themeArabic = ThemeData( diff --git a/lib/views/home/Captin/history/history_details_page.dart b/lib/views/home/Captin/history/history_details_page.dart index 1c40f95..bebaca1 100644 --- a/lib/views/home/Captin/history/history_details_page.dart +++ b/lib/views/home/Captin/history/history_details_page.dart @@ -36,7 +36,7 @@ class HistoryDetailsPage extends StatelessWidget { String mapUrl = 'https://www.google.com/maps/dir/${res['start_location']}/${res['end_location']}/'; print(mapUrl); - launchUrl1(mapUrl); + showInBrowser(mapUrl); }, child: Text( 'Trip on Map Click here'.tr, diff --git a/lib/views/home/Captin/orderCaptin/order_request_page.dart b/lib/views/home/Captin/orderCaptin/order_request_page.dart index 6ad717e..412ee0c 100644 --- a/lib/views/home/Captin/orderCaptin/order_request_page.dart +++ b/lib/views/home/Captin/orderCaptin/order_request_page.dart @@ -42,7 +42,7 @@ class OrderRequestPage extends StatelessWidget { String mapUrl = 'https://www.google.com/maps/dir/${myList[0]}/${myList[1]}/'; print(mapUrl); - launchUrl1(mapUrl); + showInBrowser(mapUrl); }, icon: const Icon(Icons.map), label: myList[20].toString() == 'haveSteps' diff --git a/lib/views/home/map_widget.dart/buttom_sheet_map_show.dart b/lib/views/home/map_widget.dart/buttom_sheet_map_show.dart index c2d75e9..73fe60e 100644 --- a/lib/views/home/map_widget.dart/buttom_sheet_map_show.dart +++ b/lib/views/home/map_widget.dart/buttom_sheet_map_show.dart @@ -81,7 +81,7 @@ GetBuilder buttomSheetMapPage() { style: AppStyle.subtitle, ), Text( - '${'You trip distance is'.tr} ${controller.distance} KM', + '${'Your trip distance is'.tr} ${controller.distance.toStringAsFixed(2)} KM', style: AppStyle.subtitle, ) ], diff --git a/lib/views/home/map_widget.dart/ride_begin_passenger.dart b/lib/views/home/map_widget.dart/ride_begin_passenger.dart index ecc2e1b..fe81d2f 100644 --- a/lib/views/home/map_widget.dart/ride_begin_passenger.dart +++ b/lib/views/home/map_widget.dart/ride_begin_passenger.dart @@ -39,6 +39,7 @@ class RideBeginPassenger extends StatelessWidget { ), Stack( children: [ + // StreamCounter(), LinearProgressIndicator( backgroundColor: AppColor.accentColor, color: controller.remainingTimeTimerRideBegin < 60 @@ -200,3 +201,39 @@ class RideBeginPassenger extends StatelessWidget { }); } } + +class StreamCounter extends StatelessWidget { + const StreamCounter({Key? key}) : super(key: key); + + @override + // Build the UI based on the timer value + Widget build(BuildContext context) { + Get.put(MapPassengerController()); + return GetBuilder(builder: (controller) { + return StreamBuilder( + initialData: 0, + stream: controller.timerController.stream, + builder: (context, snapshot) { + // Calculate the remaining time based on the current tick + final remainingTime = controller.durationToRide - snapshot.data!; + + // Format the remaining time as a string + final formattedRemainingTime = + '${(remainingTime / 60).floor()}:${(remainingTime % 60).toString().padLeft(2, '0')}'; + + // Return the UI widgets based on the remaining time + return Column( + children: [ + Text(formattedRemainingTime), + // ElevatedButton( + // onPressed: () { + // // Handle button press here + // }, + // ), + ], + ); + }, + ); + }); + } +} diff --git a/lib/views/home/profile/order_history.dart b/lib/views/home/profile/order_history.dart index 3b9fcef..ca936ce 100644 --- a/lib/views/home/profile/order_history.dart +++ b/lib/views/home/profile/order_history.dart @@ -59,7 +59,7 @@ class OrderHistory extends StatelessWidget { String mapUrl = 'https://www.google.com/maps/dir/${rides['start_location']}/${rides['end_location']}/'; // print(mapUrl); - launchUrl1(mapUrl); + showInBrowser(mapUrl); }, child: Text( 'Click here to Show it in Map',