Update: 2026-06-25 02:28:33

This commit is contained in:
Hamza-Ayed
2026-06-25 02:28:33 +03:00
parent 1ff13f09ac
commit 98a8a2ae3d
43 changed files with 992 additions and 812 deletions

View File

@@ -1,8 +1,7 @@
import 'dart:convert';
import 'package:siro_rider/constant/box_name.dart';
import 'package:siro_rider/constant/colors.dart';
import 'package:siro_rider/constant/links.dart';
import 'package:siro_rider/controller/functions/country_logic.dart';
import 'package:siro_rider/controller/functions/crud.dart';
import 'package:flutter/material.dart';
import 'package:flutter_contacts/flutter_contacts.dart';
@@ -77,9 +76,8 @@ ${AppLink.inviteRedirectUrl}?code=$couponCode&app=rider
var response = await CRUD().get(link: AppLink.getInviteDriver, payload: {
"driverId": box.read(BoxName.driverID),
});
if (response != 'failure') {
var data = jsonDecode(response);
driverInvitationData = data['message'];
if (response != 'failure' && response is Map) {
driverInvitationData = response['message'];
update();
}
} catch (e) {
@@ -93,9 +91,8 @@ ${AppLink.inviteRedirectUrl}?code=$couponCode&app=rider
.get(link: AppLink.getDriverInvitationToPassengers, payload: {
"driverId": box.read(BoxName.passengerID),
});
if (response != 'failure') {
var data = jsonDecode(response);
driverInvitationDataToPassengers = data['message'];
if (response != 'failure' && response is Map) {
driverInvitationDataToPassengers = response['message'];
update();
}
} catch (e) {
@@ -167,17 +164,14 @@ ${AppLink.inviteRedirectUrl}?code=$couponCode&app=rider
// snackPosition: SnackPosition.BOTTOM);
}
} else {
Get.snackbar('No contacts found'.tr,
'No contacts with phone numbers were found on your device.'.tr);
mySnackbarWarning('No contacts with phone numbers were found on your device.'.tr);
}
} else {
Get.snackbar('Permission denied'.tr,
'Contact permission is required to pick contacts'.tr);
mySnackbarWarning('Contact permission is required to pick contacts'.tr);
}
} catch (e) {
Log.print('Error picking contacts: $e');
Get.snackbar(
'Error'.tr, 'An error occurred while picking contacts: $e'.tr);
mySnackeBarError('An error occurred while picking contacts: $e'.tr);
}
}
@@ -187,28 +181,11 @@ ${AppLink.inviteRedirectUrl}?code=$couponCode&app=rider
Get.back();
}
/// **IMPROVEMENT**: A new robust function to format phone numbers specifically for Syria (+963).
/// It handles various user inputs gracefully to produce a standardized international format.
String _formatSyrianPhoneNumber(String phone) {
// 1. Remove all non-digit characters to clean the input.
String digitsOnly = phone.replaceAll(RegExp(r'\D'), '');
// 2. If it already starts with the country code, we assume it's correct.
if (digitsOnly.startsWith('963')) {
return '$digitsOnly';
}
// 3. If it starts with '09' (common local format), remove the leading '0'.
if (digitsOnly.startsWith('09')) {
digitsOnly = digitsOnly.substring(1);
}
// 4. Prepend the Syrian country code.
return '963$digitsOnly';
/// Formats phone number based on the current country (Syria=963, Jordan=962, Egypt=20).
String _formatPhoneByCountry(String phone) {
return CountryLogic.formatCurrentCountryPhone(phone);
}
/// **IMPROVEMENT**: This method now uses the new phone formatting logic and
/// sends a much-improved, user-friendly WhatsApp message.
void sendInviteToPassenger() async {
if (invitePhoneController.text.isEmpty ||
invitePhoneController.text.length < 9) {
@@ -217,9 +194,8 @@ ${AppLink.inviteRedirectUrl}?code=$couponCode&app=rider
}
try {
// Use the new formatting function to ensure the number is correct.
String formattedPhoneNumber =
_formatSyrianPhoneNumber(invitePhoneController.text);
_formatPhoneByCountry(invitePhoneController.text);
var response =
await CRUD().post(link: AppLink.addInvitationPassenger, payload: {
@@ -229,13 +205,9 @@ ${AppLink.inviteRedirectUrl}?code=$couponCode&app=rider
if (response != 'failure' && response is Map) {
var d = response;
Get.snackbar('Success'.tr, 'Invite sent successfully'.tr,
backgroundColor: Colors.green, colorText: Colors.white);
mySnackbarSuccess('Invite sent successfully'.tr);
// التحقق الديناميكي من مكان البيانات (V1 vs V3)
var payload = d['data'] ?? d['message'];
// إذا كان الـ message نصاً وليس خريطة (Map)، نأخذ البيانات من المستوى الأعلى
if (payload is String) {
payload = d;
}
@@ -243,7 +215,6 @@ ${AppLink.inviteRedirectUrl}?code=$couponCode&app=rider
String expirationTime = (payload['expirationTime'] ?? '').toString();
String inviteCode = (payload['inviteCode'] ?? '').toString();
// New and improved WhatsApp message for better user engagement.
String message =
"👋 ${'Hello! I\'m inviting you to try Siro.'.tr}\n\n"
"🎁 ${'Use my invitation code to get a special gift on your first ride!'.tr}\n\n"
@@ -259,16 +230,11 @@ ${AppLink.inviteRedirectUrl}?code=$couponCode&app=rider
invitePhoneController.clear();
update();
} else {
Get.snackbar(
'Error'.tr, "This phone number has already been invited.".tr,
backgroundColor: AppColor.redColor,
duration: const Duration(seconds: 4));
mySnackbarWarning("This phone number has already been invited.".tr);
}
} catch (e) {
Log.print("Error sending invite: $e");
Get.snackbar(
'Error'.tr, 'An unexpected error occurred. Please try again.'.tr,
backgroundColor: AppColor.redColor);
mySnackeBarError('An unexpected error occurred. Please try again.'.tr);
}
}
@@ -314,9 +280,8 @@ ${AppLink.inviteRedirectUrl}?code=$couponCode&app=rider
},
);
if (response != 'failure') {
var data = jsonDecode(response);
if (data['status'] == 'success') {
if (response != 'failure' && response is Map) {
if (response['status'] == 'success') {
NotificationCaptainController().addNotificationCaptain(
invitation['passengerInviterId'].toString(),
"You have got a gift for invitation".tr,
@@ -325,7 +290,7 @@ ${AppLink.inviteRedirectUrl}?code=$couponCode&app=rider
);
fetchDriverStatsPassengers(); // Refresh list
} else {
Get.snackbar('Error'.tr, data['message'] ?? 'Claim failed'.tr, backgroundColor: AppColor.redColor);
mySnackeBarError(response['message'] ?? 'Claim failed'.tr);
}
}
},