From 06905be0e9795002a9b2746046689f4675f941b6 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Mon, 16 Oct 2023 16:53:27 +0300 Subject: [PATCH] 10/16/1 --- lib/constant/box_name.dart | 1 + lib/constant/credential.dart | 3 + .../home/captin/home_captain_controller.dart | 9 - .../home/map_passenger_controller.dart | 35 ++- .../profile/profile_controller.dart | 2 +- lib/views/home/Captin/home_captin.dart | 4 +- lib/views/home/map_page.dart | 2 +- .../buttom_sheet_map_show.dart | 2 +- .../map_widget.dart/main_bottom_Menu_map.dart | 200 +++++++++--------- .../map_widget.dart/ride_begin_passenger.dart | 162 +++++++++++--- .../home/profile/passenger_profile_page.dart | 101 ++++++--- pubspec.lock | 8 - pubspec.yaml | 1 - 13 files changed, 339 insertions(+), 191 deletions(-) diff --git a/lib/constant/box_name.dart b/lib/constant/box_name.dart index 26ae147..c7d2479 100644 --- a/lib/constant/box_name.dart +++ b/lib/constant/box_name.dart @@ -6,6 +6,7 @@ class BoxName { static const String password = "password"; static const String passwordDriver = "passwordDriver"; static const String agreeTerms = "agreeTerms"; + static const String sosPhonePassenger = "sosPhonePassenger"; static const String passengerID = "pasengerID"; static const String phone = "phone"; static const String phoneDriver = "phoneDriver"; diff --git a/lib/constant/credential.dart b/lib/constant/credential.dart index 46797b2..25d0a94 100644 --- a/lib/constant/credential.dart +++ b/lib/constant/credential.dart @@ -18,6 +18,9 @@ class AppCredintials { class MyClass { static const String mapAPIKEY = 'AIzaSyCyfwRXTwSTLOFQSQgN5p7QZgGJVZnEKq0'; + static const String twilloRecoveryCode = 'TQF13XUVU2NJ3VFU8JWBWYBS'; + static const String accountSIDTwillo = 'ACb4ad857efe0903bfd6238a763a2ce4d1'; + static const String authTokenTwillo = '14f39ef4628bb8a4f18469f462f8af75'; static const String additionalText = 'additional text'; String getBasicAuthCredentials() { diff --git a/lib/controller/home/captin/home_captain_controller.dart b/lib/controller/home/captin/home_captain_controller.dart index 867fd31..a6d2f24 100644 --- a/lib/controller/home/captin/home_captain_controller.dart +++ b/lib/controller/home/captin/home_captain_controller.dart @@ -1,4 +1,3 @@ -import 'package:flutter_sms/flutter_sms.dart'; import 'package:get/get.dart'; import 'package:ride/constant/box_name.dart'; import 'dart:async'; @@ -62,14 +61,6 @@ class HomeCaptainController extends GetxController { super.onInit(); } - void sendSMSToRecipents(String message, List recipents) async { - String _result = await sendSMS(message: message, recipients: recipents) - .catchError((onError) { - print(onError); - }); - print(_result); - } - @override void dispose() { activeTimer?.cancel(); diff --git a/lib/controller/home/map_passenger_controller.dart b/lib/controller/home/map_passenger_controller.dart index 7e2a5f5..d52762a 100644 --- a/lib/controller/home/map_passenger_controller.dart +++ b/lib/controller/home/map_passenger_controller.dart @@ -17,10 +17,13 @@ import 'package:ride/views/Rate/rate_captain.dart'; import 'package:ride/views/widgets/elevated_btn.dart'; import '../../main.dart'; import '../../models/model/locations.dart'; +import '../functions/launch.dart'; class MapPassengerController extends GetxController { bool isLoading = true; TextEditingController placeController = TextEditingController(); + TextEditingController sosPhonePassengerProfile = TextEditingController(); + final sosFormKey = GlobalKey(); List data = []; List bounds = []; List places = []; @@ -80,6 +83,9 @@ class MapPassengerController extends GetxController { double progressTimerRideBegin = 0; int remainingTimeTimerRideBegin = 60; String stringRemainingTimeRideBegin = ''; + late String rideId; + late String driverToken; + int carsOrder = 0; void onChangedPassengerCount(int newValue) { selectedPassengerCount = newValue; @@ -116,6 +122,32 @@ class MapPassengerController extends GetxController { update(); } + void sendSMS(String to) async { + // Get the driver's phone number. + String driverPhone = + dataCarsLocationByPassenger['message'][carsOrder]['phone'].toString(); + + // Format the message. + String message = + 'Hi! This is ${box.read(BoxName.name)}. I am using Sefer to ride with ${dataCarsLocationByPassenger['message'][carsOrder]['first_name'].toString()} as the driver. ${dataCarsLocationByPassenger['message'][carsOrder]['first_name'].toString()} is driving a ${dataCarsLocationByPassenger['message'][carsOrder]['model'].toString()} with license plate ${dataCarsLocationByPassenger['message'][carsOrder]['license_plate'].toString()}. I am currently located at $myLocation. If you need to reach me, please contact the driver directly at $driverPhone.'; + + // Launch the URL to send the SMS. + launchCommunication('sms', to, message); + } + + void sendWhatsapp(String to) async { + // Get the driver's phone number. + String driverPhone = + dataCarsLocationByPassenger['message'][carsOrder]['phone'].toString(); + + // Format the message. + String message = + 'Hi! This is ${box.read(BoxName.name)}. I am using Sefer to ride with ${dataCarsLocationByPassenger['message'][carsOrder]['first_name'].toString()} as the driver. ${dataCarsLocationByPassenger['message'][carsOrder]['first_name'].toString()} is driving a ${dataCarsLocationByPassenger['message'][carsOrder]['model'].toString()} with license plate ${dataCarsLocationByPassenger['message'][carsOrder]['license_plate'].toString()}. I am currently located at $myLocation. If you need to reach me, please contact the driver directly at $driverPhone.'; + + // Launch the URL to send the SMS. + launchCommunication('whatsapp', to, message); + } + void changeCancelRidePageShow() { // rideConfirm == true // ? @@ -223,9 +255,6 @@ class MapPassengerController extends GetxController { update(); } - late String rideId; - late String driverToken; - int carsOrder = 0; changeConfirmRide() async { PaymentController paymentController = Get.find(); rideConfirm = true; diff --git a/lib/controller/profile/profile_controller.dart b/lib/controller/profile/profile_controller.dart index 7398845..92db26c 100644 --- a/lib/controller/profile/profile_controller.dart +++ b/lib/controller/profile/profile_controller.dart @@ -15,7 +15,7 @@ class ProfileController extends GetxController { TextEditingController txtController = TextEditingController(); List genders = ['Male', 'Female', 'Non-binary']; - String gender = ''; + String gender = 'Male'; void setGender(String value) { gender = value; diff --git a/lib/views/home/Captin/home_captin.dart b/lib/views/home/Captin/home_captin.dart index 28e7a21..04d3e2f 100644 --- a/lib/views/home/Captin/home_captin.dart +++ b/lib/views/home/Captin/home_captin.dart @@ -121,8 +121,8 @@ class HomeCaptain extends StatelessWidget { ), TextButton( onPressed: () { - homeCaptainController.sendSMSToRecipents( - 'hi from Sefer', ['+962798583052']); + // homeCaptainController.sendSMSToRecipents( + // 'hi from Sefer', ['+962798583052']); }, child: const Text('send msg')), ], diff --git a/lib/views/home/map_page.dart b/lib/views/home/map_page.dart index 80a9c60..902095c 100644 --- a/lib/views/home/map_page.dart +++ b/lib/views/home/map_page.dart @@ -151,7 +151,7 @@ class MapPage extends StatelessWidget { onTap: (argument) { controller.hidePlaces(); - controller.changeBottomSheetShown(); + // controller.changeBottomSheetShown(); // controller.bottomSheet(); }, initialCameraPosition: CameraPosition( 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 6632221..6488e74 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 @@ -327,7 +327,7 @@ GetBuilder buttomSheetMapPage() { .tr, style: AppStyle.title, ), - Container( + SizedBox( height: 200, // Set the desired height here child: CupertinoPicker( 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 b41d783..6dfe48e 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 @@ -71,24 +71,26 @@ class MainBottomMenuMap extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, 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"); - }, - ), - ), + height: 30, + child: Text( + '${'Where to'.tr} ${box.read(BoxName.name)}') + // 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"); + // }, + // ), + ), Row( mainAxisAlignment: MainAxisAlignment.center, @@ -148,96 +150,88 @@ class FavioratePlacesDialogu extends StatelessWidget { builder: (controller) => DefaultTextStyle( style: AppStyle.title, child: Center( - child: AnimatedTextKit( - animatedTexts: [ - TypewriterAnimatedText('Favorite Places'.tr), - ScaleAnimatedText( - 'Favorite Places'.tr, - ), - // TyperAnimatedText( - // 'Favorite Places'.tr, - // ), - ], - isRepeatingAnimation: true, - onTap: () async { - List favoritePlaces = - await sql.getAllData(TableName.placesFavorite); - print(favoritePlaces); - Get.defaultDialog( - title: 'Favorite Places'.tr, - content: SizedBox( - width: Get.width * .8, - height: 300, - child: favoritePlaces.isEmpty - ? Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, + child: InkWell( + onTap: () async { + List favoritePlaces = + await sql.getAllData(TableName.placesFavorite); + // print(favoritePlaces); + Get.defaultDialog( + title: 'Favorite Places'.tr, + content: SizedBox( + width: Get.width * .8, + height: 300, + child: favoritePlaces.isEmpty + ? Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Icon( + Icons.hourglass_empty_rounded, + size: 99, + color: AppColor.primaryColor, + ), + Text( + 'You Dont Have Any places yet !'.tr, + style: AppStyle.title, + ), + ], + ), + ) + : ListView.builder( + itemCount: favoritePlaces.length, + itemBuilder: (BuildContext context, int index) { + return Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, children: [ - const Icon( - Icons.hourglass_empty_rounded, - size: 99, - color: AppColor.primaryColor, + TextButton( + onPressed: () async { + await controller.getMap( + '${controller.myLocation.latitude},${controller.myLocation.longitude}', + '${favoritePlaces[index]['latitude']},${favoritePlaces[index]['longitude']}', + ); + // controller.changePickerShown(); + controller.showBottomSheet1(); + Get.back(); + controller.showBottomSheet1(); + }, + child: Text( + favoritePlaces[index]['name'], + style: AppStyle.title, + ), ), - Text( - 'You Dont Have Any places yet !'.tr, - style: AppStyle.title, + IconButton( + onPressed: () async { + await sql.deleteData( + TableName.placesFavorite, + favoritePlaces[index]['id']); + Get.back(); + // ignore: use_build_context_synchronously + Toast.show( + context, + '${'You are Delete'.tr} ${favoritePlaces[index]['name']} from your list', + AppColor.redColor); + // Get.snackbar('Deleted'.tr, + // '${'You are Delete'.tr} ${favoritePlaces[index]['name']} from your list', + // backgroundColor: + // AppColor.accentColor); + }, + icon: const Icon(Icons.favorite_outlined), ), ], - ), - ) - : ListView.builder( - itemCount: favoritePlaces.length, - itemBuilder: (BuildContext context, int index) { - return Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - TextButton( - onPressed: () async { - await controller.getMap( - '${controller.myLocation.latitude},${controller.myLocation.longitude}', - '${favoritePlaces[index]['latitude']},${favoritePlaces[index]['longitude']}', - ); - // controller.changePickerShown(); - controller.showBottomSheet1(); - Get.back(); - controller.showBottomSheet1(); - }, - child: Text( - favoritePlaces[index]['name'], - style: AppStyle.title, - ), - ), - IconButton( - onPressed: () async { - await sql.deleteData( - TableName.placesFavorite, - favoritePlaces[index]['id']); - Get.back(); - // ignore: use_build_context_synchronously - Toast.show( - context, - '${'You are Delete'.tr} ${favoritePlaces[index]['name']} from your list', - AppColor.redColor); - // Get.snackbar('Deleted'.tr, - // '${'You are Delete'.tr} ${favoritePlaces[index]['name']} from your list', - // backgroundColor: - // AppColor.accentColor); - }, - icon: - const Icon(Icons.favorite_outlined), - ), - ], - ); - }, - ), - ), - cancel: MyElevatedButton( - title: 'Back'.tr, onPressed: () => Get.back()), - ); - }, + ); + }, + ), + ), + cancel: MyElevatedButton( + title: 'Back'.tr, onPressed: () => Get.back()), + ); + }, + child: Text( + '\u{1F3D8} ' 'Favorite Places'.tr, + style: AppStyle.title, ), - ), + )), )); } } 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 be73c1c..ef5619c 100644 --- a/lib/views/home/map_widget.dart/ride_begin_passenger.dart +++ b/lib/views/home/map_widget.dart/ride_begin_passenger.dart @@ -1,5 +1,8 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:ride/constant/box_name.dart'; +import 'package:ride/controller/profile/profile_controller.dart'; +import 'package:ride/main.dart'; import 'package:ride/views/widgets/elevated_btn.dart'; import '../../../constant/colors.dart'; @@ -13,6 +16,7 @@ class RideBeginPassenger extends StatelessWidget { @override Widget build(BuildContext context) { + ProfileController profileController = Get.put(ProfileController()); return GetBuilder(builder: (controller) { if (controller.rideTimerBegin) { return Positioned( @@ -26,6 +30,7 @@ class RideBeginPassenger extends StatelessWidget { child: Padding( padding: const EdgeInsets.all(8.0), child: Column( + mainAxisAlignment: MainAxisAlignment.center, children: [ Text( 'You will arrive to your destination after '.tr, @@ -50,34 +55,137 @@ class RideBeginPassenger extends StatelessWidget { ) ], ), - controller.remainingTimeTimerRideBegin < 5 - ? MyElevatedButton( - title: - 'If you in destination Now. Press finish The Ride', - onPressed: () async { - //todo finish the trip and rest all counter ,start new counter of the trip time + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + IconButton( + onPressed: () { + if (box.read(BoxName.sosPhonePassenger).toString() == + '') { + Get.defaultDialog( + title: 'You dont Add Emergency Phone Yet!'.tr, + content: Column( + children: [ + Form( + key: controller.sosFormKey, + child: TextFormField( + keyboardType: TextInputType + .phone, // Set the keyboard type to phone + validator: (value) { + if (value!.isEmpty || + value.length < 10) { + return 'Please enter a phone number'; + } + // Add additional validation if needed + return null; + }, + decoration: const InputDecoration( + border: OutlineInputBorder(), + hintText: 'Type here', + ), + ), + ) + ], + ), + confirm: MyElevatedButton( + title: 'Add Phone'.tr, + onPressed: () async { + await profileController + .updatField('sosPhone'); + box.write( + BoxName.sosPhonePassenger, + profileController + .prfoileData['sosPhone']); + })); + } else { + controller + .sendSMS(box.read(BoxName.sosPhonePassenger)); + } + }, + icon: const Icon( + Icons.sos_rounded, + color: AppColor.redColor, + ), + ), + IconButton( + onPressed: () { + if (box.read(BoxName.sosPhonePassenger).toString() == + '') { + Get.defaultDialog( + title: 'You dont Add Emergency Phone Yet!'.tr, + content: Column( + children: [ + Form( + key: controller.sosFormKey, + child: TextFormField( + keyboardType: TextInputType + .phone, // Set the keyboard type to phone + validator: (value) { + if (value!.isEmpty || + value.length < 10) { + return 'Please enter a phone number'; + } + // Add additional validation if needed + return null; + }, + decoration: const InputDecoration( + border: OutlineInputBorder(), + hintText: 'Type here', + ), + ), + ) + ], + ), + confirm: MyElevatedButton( + title: 'Add Phone'.tr, + onPressed: () async { + await profileController + .updatField('sosPhone'); + box.write( + BoxName.sosPhonePassenger, + profileController + .prfoileData['sosPhone']); + })); + } else { + controller.sendWhatsapp( + box.read(BoxName.sosPhonePassenger)); + } + }, + icon: const Icon( + Icons.ring_volume, + color: AppColor.blueColor, + ), + ), + ], + ) + // controller.remainingTimeTimerRideBegin < 5 + // ? MyElevatedButton( + // title: + // 'If you in destination Now. Press finish The Ride', + // onPressed: () async { + //todo finish the trip and rest all counter ,start new counter of the trip time - // await CRUD() - // .post(link: AppLink.updateRides, payload: { - // 'id': controller.rideId, - // 'rideTimeStart': DateTime.now().toString(), - // 'status': 'Applied' - // }); - // controller.driverArrivePassenger(); - // // Send notification to driver to alert him that trip is begin - // FirebaseMessagesController() - // .sendNotificationToAnyWithoutData( - // 'BeginTrip', - // box.read(BoxName.name).toString(), - // controller.driverToken.toString(), - // ); - // print(controller.driverToken.toString()); - // Get.defaultDialog( - // title: 'The Ride is Begin'.tr, - // backgroundColor: AppColor.greenColor, - // ); - }) - : const SizedBox() + // await CRUD() + // .post(link: AppLink.updateRides, payload: { + // 'id': controller.rideId, + // 'rideTimeStart': DateTime.now().toString(), + // 'status': 'Applied' + // }); + // controller.driverArrivePassenger(); + // // Send notification to driver to alert him that trip is begin + // FirebaseMessagesController() + // .sendNotificationToAnyWithoutData( + // 'BeginTrip', + // box.read(BoxName.name).toString(), + // 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/home/profile/passenger_profile_page.dart b/lib/views/home/profile/passenger_profile_page.dart index e46d731..430a9ba 100644 --- a/lib/views/home/profile/passenger_profile_page.dart +++ b/lib/views/home/profile/passenger_profile_page.dart @@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:ride/constant/box_name.dart'; +import 'package:ride/constant/colors.dart'; import 'package:ride/constant/style.dart'; import 'package:ride/controller/profile/profile_controller.dart'; import 'package:ride/main.dart'; @@ -106,23 +107,27 @@ class PassengerProfilePage extends StatelessWidget { .toString()), onTap: () { Get.defaultDialog( + barrierDismissible: true, title: 'Update Education'.tr, - content: Column( - children: [ - EducationDegreePicker(), - MyElevatedButton( - title: 'Update Education'.tr, - onPressed: () { - controller.updateColumn({ - 'id': controller.prfoileData['id'] - .toString(), - 'education': - controller.selectedDegree, - }); - Get.back(); - }, - ) - ], + content: SizedBox( + height: 200, + child: Column( + children: [ + EducationDegreePicker(), + ], + ), + ), + confirm: MyElevatedButton( + title: 'Update Education'.tr, + onPressed: () { + controller.updateColumn({ + 'id': controller.prfoileData['id'] + .toString(), + 'education': + controller.selectedDegree, + }); + Get.back(); + }, )); }, ), @@ -160,6 +165,25 @@ class PassengerProfilePage extends StatelessWidget { controller.updatField('maritalStatus'); }, ), + ListTile( + title: Text( + 'SOS Phone'.tr, + style: AppStyle.title, + ), + leading: const Icon( + Icons.sos, + color: AppColor.redColor, + size: 35, + ), + trailing: const Icon(Icons.arrow_forward_ios), + subtitle: Text(controller.prfoileData['sosPhone'] + .toString()), + onTap: () async { + await controller.updatField('sosPhone'); + box.write(BoxName.sosPhonePassenger, + controller.prfoileData['sosPhone']); + }, + ), ], ), ), @@ -189,14 +213,17 @@ class GenderPicker extends StatelessWidget { @override Widget build(BuildContext context) { - return CupertinoPicker( - itemExtent: 32.0, - onSelectedItemChanged: (int index) { - controller.setGender(genderOptions[index]); - }, - children: genderOptions.map((String value) { - return Text(value); - }).toList(), + return SizedBox( + height: 100, + child: CupertinoPicker( + itemExtent: 32.0, + onSelectedItemChanged: (int index) { + controller.setGender(genderOptions[index]); + }, + children: genderOptions.map((String value) { + return Text(value); + }).toList(), + ), ); } } @@ -216,17 +243,21 @@ class EducationDegreePicker extends StatelessWidget { @override Widget build(BuildContext context) { - return CupertinoPicker( - // backgroundColor: AppColor.accentColor, - looping: true, - squeeze: 2, diameterRatio: 2, - itemExtent: 32.0, - onSelectedItemChanged: (int index) { - controller.setDegree(degreeOptions[index]); - }, - children: degreeOptions.map((String value) { - return Text(value); - }).toList(), + return SizedBox( + height: 200, + child: CupertinoPicker( + // backgroundColor: AppColor.accentColor, + // looping: true, + squeeze: 2, + // diameterRatio: 5, + itemExtent: 32, + onSelectedItemChanged: (int index) { + controller.setDegree(degreeOptions[index]); + }, + children: degreeOptions.map((String value) { + return Text(value); + }).toList(), + ), ); } } diff --git a/pubspec.lock b/pubspec.lock index 9553356..836c2da 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -326,14 +326,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.0" - flutter_sms: - dependency: "direct main" - description: - name: flutter_sms - sha256: "2fe5f584f02596343557eeca56348f9b82413fefe83a423fab880cdbdf54d8d8" - url: "https://pub.dev" - source: hosted - version: "2.3.3" flutter_spinkit: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 1f7128c..73f18a9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,7 +37,6 @@ dependencies: flutter_launcher_icons: ^0.13.1 crypto: ^3.0.3 flutter_rating_bar: ^4.0.1 - flutter_sms: ^2.3.3 dev_dependencies: