Update: 2026-06-25 02:28:33
This commit is contained in:
@@ -9,6 +9,7 @@ import 'package:siro_rider/constant/colors.dart';
|
||||
import 'package:siro_rider/constant/links.dart';
|
||||
import 'package:siro_rider/controller/functions/crud.dart';
|
||||
import 'package:siro_rider/main.dart';
|
||||
import 'package:siro_rider/views/widgets/error_snakbar.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:mime/mime.dart';
|
||||
|
||||
@@ -39,26 +40,11 @@ class ComplaintController extends GetxController {
|
||||
// --- دالة مخصصة لعرض إشعارات Snackbar بشكل جميل ---
|
||||
void _showCustomSnackbar(String title, String message,
|
||||
{bool isError = false}) {
|
||||
Get.snackbar(
|
||||
'', // العنوان سيتم التعامل معه عبر titleText
|
||||
'', // الرسالة سيتم التعامل معها عبر messageText
|
||||
titleText: Text(title.tr,
|
||||
style: const TextStyle(
|
||||
color: Colors.white, fontWeight: FontWeight.bold, fontSize: 16)),
|
||||
messageText: Text(message.tr,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 14)),
|
||||
backgroundColor: isError
|
||||
? AppColor.redColor.withOpacity(0.95)
|
||||
: const Color.fromARGB(255, 6, 148, 79).withOpacity(0.95),
|
||||
icon: Icon(isError ? Icons.error_outline : Icons.check_circle_outline,
|
||||
color: Colors.white, size: 28),
|
||||
borderRadius: 12,
|
||||
margin: const EdgeInsets.all(15),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 18),
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
duration: const Duration(seconds: 4),
|
||||
colorText: Colors.white,
|
||||
);
|
||||
if (isError) {
|
||||
mySnackeBarError(message.tr);
|
||||
} else {
|
||||
mySnackbarSuccess(message.tr);
|
||||
}
|
||||
}
|
||||
|
||||
// --- هذه الدالة تبقى كما هي لجلب بيانات الرحلة ---
|
||||
@@ -69,7 +55,7 @@ class ComplaintController extends GetxController {
|
||||
'passengerId': box.read(BoxName.passengerID).toString(),
|
||||
});
|
||||
if (res != 'failure') {
|
||||
var d = jsonDecode(res)['message'];
|
||||
var d = res['message'];
|
||||
feedBack = d;
|
||||
}
|
||||
isLoading = false;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:siro_rider/constant/box_name.dart';
|
||||
import 'package:siro_rider/constant/links.dart';
|
||||
import 'package:siro_rider/controller/functions/crud.dart';
|
||||
import 'package:siro_rider/main.dart';
|
||||
import 'package:siro_rider/views/widgets/error_snakbar.dart';
|
||||
|
||||
class InvitesRewardsController extends GetxController {
|
||||
bool isLoading = false;
|
||||
@@ -70,20 +71,20 @@ class InvitesRewardsController extends GetxController {
|
||||
}
|
||||
);
|
||||
|
||||
Get.back(); // close loading
|
||||
Navigator.maybeOf(Get.context!)?.pop(); // close loading dialog only
|
||||
|
||||
if (response != 'failure') {
|
||||
if (response['status'] == 'success') {
|
||||
Get.snackbar("Success".tr, "You have been successfully referred!".tr, backgroundColor: Colors.green, colorText: Colors.white);
|
||||
mySnackbarSuccess("You have been successfully referred!".tr);
|
||||
} else {
|
||||
Get.snackbar("Notice".tr, response['message'] ?? "Could not add invite".tr);
|
||||
mySnackbarWarning(response['message'] ?? "Could not add invite".tr);
|
||||
}
|
||||
} else {
|
||||
Get.snackbar("Error".tr, "Network error occurred".tr);
|
||||
mySnackeBarError("Network error occurred".tr);
|
||||
}
|
||||
} catch (e) {
|
||||
Get.back(); // close loading
|
||||
Get.snackbar("Error".tr, "Network error occurred".tr);
|
||||
Navigator.maybeOf(Get.context!)?.pop(); // close loading dialog only
|
||||
mySnackeBarError("Network error occurred".tr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user