Update codebase
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import 'package:tripz_driver/constant/currency.dart';
|
||||
import 'package:siro_driver/constant/currency.dart';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
@@ -7,15 +7,15 @@ import 'package:flutter_contacts/contact.dart';
|
||||
import 'package:flutter_contacts/flutter_contacts.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:local_auth/local_auth.dart';
|
||||
import 'package:tripz_driver/constant/box_name.dart';
|
||||
import 'package:tripz_driver/constant/links.dart';
|
||||
import 'package:tripz_driver/controller/functions/crud.dart';
|
||||
import 'package:tripz_driver/controller/home/payment/captain_wallet_controller.dart';
|
||||
import 'package:tripz_driver/print.dart';
|
||||
import 'package:tripz_driver/controller/functions/country_logic.dart';
|
||||
import 'package:tripz_driver/main.dart';
|
||||
import 'package:tripz_driver/views/widgets/error_snakbar.dart';
|
||||
import 'package:tripz_driver/views/widgets/mydialoug.dart';
|
||||
import 'package:siro_driver/constant/box_name.dart';
|
||||
import 'package:siro_driver/constant/links.dart';
|
||||
import 'package:siro_driver/controller/functions/crud.dart';
|
||||
import 'package:siro_driver/controller/home/payment/captain_wallet_controller.dart';
|
||||
import 'package:siro_driver/print.dart';
|
||||
import 'package:siro_driver/controller/functions/country_logic.dart';
|
||||
import 'package:siro_driver/main.dart';
|
||||
import 'package:siro_driver/views/widgets/error_snakbar.dart';
|
||||
import 'package:siro_driver/views/widgets/mydialoug.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
import '../../firebase/local_notification.dart';
|
||||
@@ -43,10 +43,10 @@ class InviteController extends GetxController {
|
||||
Future<void> shareDriverCode() async {
|
||||
if (driverCouponCode != null) {
|
||||
final String shareText =
|
||||
'''Join Tripz as a driver using my referral code!
|
||||
'''Join Siro as a driver using my referral code!
|
||||
Use code: $driverCouponCode
|
||||
Download the Tripz Driver app now and earn rewards:
|
||||
https://tripzmove.com/invite.php?code=$driverCouponCode&app=driver
|
||||
Download the Siro Captain app now and earn rewards:
|
||||
${AppLink.driverDownloadLinks}
|
||||
''';
|
||||
await Share.share(shareText);
|
||||
}
|
||||
@@ -54,10 +54,10 @@ https://tripzmove.com/invite.php?code=$driverCouponCode&app=driver
|
||||
|
||||
Future<void> sharePassengerCode() async {
|
||||
if (couponCode != null) {
|
||||
final String shareText = '''Get a discount on your first Tripz ride!
|
||||
final String shareText = '''Get a discount on your first Siro ride!
|
||||
Use my referral code: $couponCode
|
||||
Download the Tripz app now and enjoy your ride:
|
||||
https://tripzmove.com/invite.php?code=$couponCode&app=rider
|
||||
Download the Siro app now and enjoy your ride:
|
||||
https://siromove.com/invite.php?code=$couponCode&app=rider
|
||||
''';
|
||||
await Share.share(shareText);
|
||||
}
|
||||
@@ -66,62 +66,53 @@ https://tripzmove.com/invite.php?code=$couponCode&app=rider
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
// **MODIFIED**: Sync contacts automatically on controller initialization.
|
||||
syncContactsToServerOnce();
|
||||
// لا نقرأ دفتر الهاتف هنا. القراءة تحدث فقط حين يطلب الكابتن
|
||||
// اختيار جهة اتصال — انظر loadDeviceContacts أدناه.
|
||||
// fetchDriverStats();
|
||||
}
|
||||
|
||||
// --- NEW LOGIC: ONE-TIME CONTACTS SYNC ---
|
||||
// --- قراءة جهات الاتصال محلياً، بطلب المستخدم وحده ---
|
||||
|
||||
/// **NEW**: Syncs all phone contacts to the server, but only runs once per user.
|
||||
Future<void> syncContactsToServerOnce() async {
|
||||
final String syncFlagKey = 'contactsSynced_${box.read(BoxName.driverID)}';
|
||||
|
||||
// 1. Check if contacts have already been synced for this user.
|
||||
if (box.read(syncFlagKey) == true) {
|
||||
print("Contacts have already been synced for this user.");
|
||||
return;
|
||||
}
|
||||
/// كان هنا `syncContactsToServerOnce`: يقرأ دفتر هاتف الكابتن كاملاً
|
||||
/// تلقائياً عند فتح شاشة الدعوة، ويرفع **كل** اسم ورقم إلى
|
||||
/// `ride/egyptPhones/syrianAdd.php` — طلب لكل جهة اتصال.
|
||||
///
|
||||
/// أُزيل الرفع بالكامل، ولثلاثة أسباب لا واحد:
|
||||
///
|
||||
/// ١) سياسة Google Play: رفع دفتر العناوين جملةً يتطلب إفصاحاً بارزاً
|
||||
/// وموافقة صريحة، وإذن النظام وحده لا يكفي. والتطبيق موقوف أصلاً.
|
||||
///
|
||||
/// ٢) البيانات ليست بيانات الكابتن ليتبرّع بها: هي أسماء وأرقام أطراف
|
||||
/// ثالثة لم تُستأذن ولا تعلم بوجود سيرو.
|
||||
///
|
||||
/// ٣) لا ميزة تعتمد عليها. الدعوة تعمل بالمشاركة أو باختيار جهة واحدة
|
||||
/// عمداً، وكلاهما لا يحتاج نسخة من الدفتر على السيرفر.
|
||||
///
|
||||
/// ما بقي هنا قراءة محلية بحتة لعرض قائمة يختار منها الكابتن — لا
|
||||
/// شيء يغادر الجهاز.
|
||||
Future<void> loadDeviceContacts() async {
|
||||
if (contactMaps.isNotEmpty) return; // مُحمّلة سلفاً في هذه الجلسة
|
||||
|
||||
try {
|
||||
// 2. Request permission and fetch all contacts.
|
||||
if (await FlutterContacts.requestPermission(readonly: true)) {
|
||||
// mySnackbarSuccess('Starting contacts sync in background...'.tr);
|
||||
final List<Contact> allContacts =
|
||||
await FlutterContacts.getContacts(withProperties: true);
|
||||
// **FIX**: Assign fetched contacts to the class variable.
|
||||
contacts = allContacts;
|
||||
contactMaps.value = contacts.map((contact) {
|
||||
return {
|
||||
'name': contact.displayName,
|
||||
'phones':
|
||||
contact.phones.map((phone) => phone.normalizedNumber).toList(),
|
||||
'emails': contact.emails.map((email) => email.address).toList(),
|
||||
};
|
||||
}).toList();
|
||||
contactMaps.value = allContacts
|
||||
.where((c) => c.phones.isNotEmpty)
|
||||
.map((contact) => {
|
||||
'name': contact.displayName,
|
||||
'phones': contact.phones
|
||||
.map((phone) => phone.normalizedNumber)
|
||||
.toList(),
|
||||
'emails':
|
||||
contact.emails.map((email) => email.address).toList(),
|
||||
})
|
||||
.toList();
|
||||
update();
|
||||
|
||||
// 3. Loop through contacts and save them to the server.
|
||||
for (var contact in allContacts) {
|
||||
if (contact.phones.isNotEmpty) {
|
||||
// Use the normalized phone number for consistency.
|
||||
var phone = contact.phones.first.normalizedNumber;
|
||||
if (phone.isNotEmpty) {
|
||||
CRUD().post(link: AppLink.savePhonesSyria, payload: {
|
||||
"driverId": box.read(BoxName.driverID), // Associate with driver
|
||||
"name": contact.displayName ?? 'No Name',
|
||||
"phone": phone,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. After a successful sync, set the flag to prevent future syncs.
|
||||
await box.write(syncFlagKey, true);
|
||||
// mySnackbarSuccess('Contacts sync completed successfully!'.tr);
|
||||
}
|
||||
} catch (e) {
|
||||
// mySnackbarError('An error occurred during contact sync: $e'.tr);
|
||||
// قراءة دفتر الهاتف ليست حرجة — الدعوة تعمل بالمشاركة أيضاً.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -494,7 +485,7 @@ https://tripzmove.com/invite.php?code=$couponCode&app=rider
|
||||
var d = response;
|
||||
mySnackbarSuccess('Invite sent successfully'.tr);
|
||||
String inviteCode = d['message']['inviteCode'].toString();
|
||||
String message = '${'*Tripz DRIVER CODE*'.tr}\n\n'
|
||||
String message = '${'*Siro DRIVER CODE*'.tr}\n\n'
|
||||
'${"Use this code in registration".tr}\n'
|
||||
'${"To get a gift for both".tr}\n\n'
|
||||
'${"The period of this code is 24 hours".tr}\n\n'
|
||||
@@ -539,7 +530,7 @@ https://tripzmove.com/invite.php?code=$couponCode&app=rider
|
||||
mySnackbarSuccess('Invite sent successfully'.tr);
|
||||
String inviteCode = d['message']['inviteCode'].toString();
|
||||
|
||||
String message = '${'*Tripz APP CODE*'.tr}\n\n'
|
||||
String message = '${'*Siro APP CODE*'.tr}\n\n'
|
||||
'${"Use this code in registration".tr}\n\n'
|
||||
'${"To get a gift for both".tr}\n\n'
|
||||
'${"The period of this code is 24 hours".tr}\n\n'
|
||||
|
||||
Reference in New Issue
Block a user