8/27/1
This commit is contained in:
@@ -35,44 +35,64 @@ class InviteController extends GetxController {
|
||||
var data = jsonDecode(response);
|
||||
driverInvitationData = data['message'];
|
||||
update();
|
||||
// print('driverInitationData: $driverInitationData');
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error fetching driver stats: $e');
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
void selectPhone(String phone) {
|
||||
if (box.read(BoxName.countryCode) == 'Egypt') {
|
||||
invitePhoneController.text = phone;
|
||||
update();
|
||||
Get.back();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> pickContact() async {
|
||||
Future<void> saveContactsToServer() async {
|
||||
try {
|
||||
// TODO: Implement the actual server upload logic here
|
||||
// Simulating a server request
|
||||
await Future.delayed(Duration(seconds: 2));
|
||||
Get.snackbar('Success'.tr,
|
||||
'${selectedContacts.length} contacts saved to server'.tr);
|
||||
} catch (e) {
|
||||
Get.snackbar('Error'.tr,
|
||||
'An error occurred while saving contacts to server: $e'.tr);
|
||||
}
|
||||
}
|
||||
|
||||
List<Contact> contacts = <Contact>[];
|
||||
List<Contact> selectedContacts = <Contact>[];
|
||||
RxList<Map<String, dynamic>> contactMaps = <Map<String, dynamic>>[].obs;
|
||||
|
||||
Future<void> pickContacts() async {
|
||||
try {
|
||||
print('Requesting contact permission...');
|
||||
if (await FlutterContacts.requestPermission(readonly: true)) {
|
||||
print('Permission granted. Opening external contact picker...');
|
||||
final Contact? contact = await FlutterContacts.openExternalPick();
|
||||
if (contact != null) {
|
||||
print('Contact picked: ${contact.displayName}');
|
||||
if (contact.phones.isNotEmpty) {
|
||||
print('Phone number found: ${contact.phones.first.number}');
|
||||
invitePhoneController.text = contact.phones.first.number;
|
||||
update();
|
||||
} else {
|
||||
print('Selected contact has no phone number.');
|
||||
Get.snackbar('No phone number'.tr,
|
||||
'The selected contact does not have a phone number.'.tr);
|
||||
}
|
||||
} else {
|
||||
print('No contact selected or picker was cancelled.');
|
||||
Get.snackbar('No contact selected'.tr, 'Please select a contact'.tr);
|
||||
final List<Contact> fetchedContacts =
|
||||
await FlutterContacts.getContacts(withProperties: true);
|
||||
contacts = fetchedContacts;
|
||||
|
||||
// Convert contacts to a list of maps
|
||||
contactMaps.value = fetchedContacts.map((contact) {
|
||||
return {
|
||||
'name': contact.displayName,
|
||||
'phones':
|
||||
contact.phones.map((phone) => phone.normalizedNumber).toList(),
|
||||
'emails': contact.emails.map((email) => email.address).toList(),
|
||||
};
|
||||
}).toList();
|
||||
update();
|
||||
|
||||
if (contacts.isEmpty) {
|
||||
Get.snackbar('No contacts available'.tr,
|
||||
'Please add contacts to your phone.'.tr);
|
||||
}
|
||||
} else {
|
||||
print('Permission denied by user or system.');
|
||||
Get.snackbar('Permission denied'.tr,
|
||||
'Contact permission is required to pick a contact'.tr);
|
||||
'Contact permission is required to pick contacts'.tr);
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error picking contact: $e');
|
||||
print('Stack trace: ${StackTrace.current}');
|
||||
Get.snackbar(
|
||||
'Error'.tr, 'An error occurred while picking a contact: $e'.tr);
|
||||
'Error'.tr, 'An error occurred while picking contacts: $e'.tr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,6 +136,33 @@ class InviteController extends GetxController {
|
||||
);
|
||||
}
|
||||
|
||||
savePhoneToServer() async {
|
||||
for (var i = 0; i < contactMaps.length; i++) {
|
||||
var phones = contactMaps[i]['phones'];
|
||||
if (phones != null && phones.isNotEmpty && phones[0].isNotEmpty) {
|
||||
var res = await CRUD().post(link: AppLink.savePhones, payload: {
|
||||
"name": contactMaps[i]['name'] ?? 'none',
|
||||
"phones": phones[0] ?? 'none',
|
||||
"phones2": phones.join(', ') ??
|
||||
'none', // Convert List<String> to a comma-separated string
|
||||
});
|
||||
if (res != 'failure') {}
|
||||
} else {}
|
||||
}
|
||||
}
|
||||
|
||||
String formatPhoneNumber(String input) {
|
||||
// Remove any non-digit characters
|
||||
String digitsOnly = input.replaceAll(RegExp(r'\D'), '');
|
||||
|
||||
// Ensure the number starts with the country code
|
||||
if (digitsOnly.startsWith('20')) {
|
||||
digitsOnly = digitsOnly.substring(1);
|
||||
}
|
||||
|
||||
return digitsOnly;
|
||||
}
|
||||
|
||||
void sendInvite() async {
|
||||
if (invitePhoneController.text.isEmpty) {
|
||||
Get.snackbar('Error', 'Please enter an phone address'.tr);
|
||||
@@ -123,11 +170,13 @@ class InviteController extends GetxController {
|
||||
}
|
||||
|
||||
// try {
|
||||
String phoneNumber = formatPhoneNumber(invitePhoneController.text);
|
||||
|
||||
var response = await CRUD().post(link: AppLink.addInviteDriver, payload: {
|
||||
"driverId": box.read(BoxName.driverID),
|
||||
"inviterDriverPhone": '+2${invitePhoneController.text}'
|
||||
"inviterDriverPhone": phoneNumber
|
||||
});
|
||||
Log.print('response: ${response}');
|
||||
|
||||
if (response != 'failure') {
|
||||
var d = jsonDecode(response);
|
||||
Get.snackbar('Success', 'Invite sent successfully'.tr);
|
||||
@@ -142,8 +191,7 @@ class InviteController extends GetxController {
|
||||
'*Android:* https://play.google.com/store/apps/details?id=com.sefer_driver\n\n\n'
|
||||
'*iOS:* https://apps.apple.com/ae/app/sefer-driver/id6502189302';
|
||||
|
||||
launchCommunication(
|
||||
'whatsapp', '+2${invitePhoneController.text}', message);
|
||||
launchCommunication('whatsapp', '+2$phoneNumber', message);
|
||||
|
||||
invitePhoneController.clear();
|
||||
} else {
|
||||
@@ -152,7 +200,6 @@ class InviteController extends GetxController {
|
||||
duration: const Duration(seconds: 4));
|
||||
}
|
||||
// } catch (e) {
|
||||
// print('Error sending invite: $e');
|
||||
// Get.snackbar('Error', 'An error occurred'.tr);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:convert';
|
||||
|
||||
import 'package:SEFER/constant/colors.dart';
|
||||
import 'package:SEFER/controller/functions/location_background_controller.dart';
|
||||
import 'package:SEFER/print.dart';
|
||||
import 'package:SEFER/views/auth/captin/cards/sms_signup.dart';
|
||||
import 'package:SEFER/views/widgets/elevated_btn.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -54,6 +55,7 @@ class LoginDriverController extends GetxController {
|
||||
'email': email,
|
||||
'id': driverID,
|
||||
});
|
||||
|
||||
print(res);
|
||||
if (res == 'failure') {
|
||||
//Failure
|
||||
|
||||
@@ -80,8 +80,8 @@ class RegisterCaptainController extends GetxController {
|
||||
}
|
||||
|
||||
bool isValidEgyptianPhoneNumber(String phoneNumber) {
|
||||
// Remove any whitespace from the phone number
|
||||
phoneNumber = phoneNumber.replaceAll(RegExp(r'\s+'), '');
|
||||
// Remove any non-digit characters (spaces, dashes, etc.)
|
||||
phoneNumber = phoneNumber.replaceAll(RegExp(r'\D+'), '');
|
||||
|
||||
// Check if the phone number has exactly 11 digits
|
||||
if (phoneNumber.length != 11) {
|
||||
@@ -89,7 +89,7 @@ class RegisterCaptainController extends GetxController {
|
||||
}
|
||||
|
||||
// Check if the phone number starts with 010, 011, 012, or 015
|
||||
RegExp validPrefixes = RegExp(r'^01[0125]');
|
||||
RegExp validPrefixes = RegExp(r'^01[0125]\d{8}$');
|
||||
|
||||
return validPrefixes.hasMatch(phoneNumber);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user