11/17/1
This commit is contained in:
@@ -4,8 +4,8 @@ import 'package:SEFER/constant/box_name.dart';
|
||||
import 'package:SEFER/constant/colors.dart';
|
||||
import 'package:SEFER/constant/links.dart';
|
||||
import 'package:SEFER/controller/functions/crud.dart';
|
||||
import 'package:SEFER/controller/home/payment/captain_wallet_controller.dart';
|
||||
import 'package:SEFER/controller/payment/payment_controller.dart';
|
||||
import 'package:SEFER/views/widgets/mysnakbar.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_contacts/contact.dart';
|
||||
import 'package:flutter_contacts/flutter_contacts.dart';
|
||||
@@ -13,6 +13,7 @@ import 'package:get/get.dart';
|
||||
import 'package:share/share.dart';
|
||||
|
||||
import '../../../main.dart';
|
||||
import '../../../print.dart';
|
||||
import '../../../views/widgets/my_dialog.dart';
|
||||
import '../../functions/launch.dart';
|
||||
import '../../notification/notification_captain_controller.dart';
|
||||
@@ -117,23 +118,49 @@ Download the SEFER app now and enjoy your ride!
|
||||
|
||||
Future<void> pickContacts() async {
|
||||
try {
|
||||
// Request contacts permission
|
||||
if (await FlutterContacts.requestPermission(readonly: true)) {
|
||||
final List<Contact> fetchedContacts =
|
||||
await FlutterContacts.getContacts(withProperties: true);
|
||||
contacts = fetchedContacts;
|
||||
// Fetch all contacts with full properties
|
||||
final List<Contact> allContacts = await FlutterContacts.getContacts(
|
||||
withProperties: true,
|
||||
withThumbnail: false,
|
||||
withPhoto: true,
|
||||
);
|
||||
|
||||
// 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();
|
||||
// Check if contacts are available
|
||||
if (allContacts.isNotEmpty) {
|
||||
// Store the contacts
|
||||
contacts = allContacts;
|
||||
Log.print('contacts: $contacts');
|
||||
|
||||
if (contacts.isEmpty) {
|
||||
// Convert contacts to a list of maps
|
||||
contactMaps.value = await Future.wait(contacts.map((contact) async {
|
||||
Log.print('Contact name: ${contact.displayName}');
|
||||
|
||||
// Fetch phone numbers separately
|
||||
final phones = await contact.phones;
|
||||
Log.print('Contact phones: $phones');
|
||||
|
||||
// Fetch email addresses separately
|
||||
final emails = await contact.emails;
|
||||
Log.print('Contact emails: $emails');
|
||||
|
||||
// Handle empty or null values
|
||||
return {
|
||||
'name': contact.displayName ?? '',
|
||||
'phones': phones
|
||||
.where((phone) => phone.normalizedNumber != null)
|
||||
.map((phone) => phone.normalizedNumber ?? 'No number')
|
||||
.toList(),
|
||||
'emails': emails
|
||||
.where((email) => email.address != null)
|
||||
.map((email) => email.address ?? 'No email')
|
||||
.toList(),
|
||||
};
|
||||
}).toList());
|
||||
|
||||
update();
|
||||
} else {
|
||||
Get.snackbar('No contacts available'.tr,
|
||||
'Please add contacts to your phone.'.tr);
|
||||
}
|
||||
@@ -225,8 +252,10 @@ Download the SEFER app now and enjoy your ride!
|
||||
}
|
||||
|
||||
void sendInviteToPassenger() async {
|
||||
if (invitePhoneController.text.isEmpty) {
|
||||
Get.snackbar('Error', 'Please enter an phone address'.tr);
|
||||
if (invitePhoneController.text.isEmpty ||
|
||||
invitePhoneController.text.length < 11) {
|
||||
mySnackeBarError('Please enter a correct phone'.tr);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user