uncommented the code and resolved errors
#2
Merged
waqas.khurshid
merged 1 commits from kyc_API_Implementation into pre_developmnet_branch 2 weeks ago
@ -1,105 +1,106 @@
|
||||
// import 'package:flutter/cupertino.dart';
|
||||
// import 'package:flutter_contacts/flutter_contacts.dart';
|
||||
// import 'package:get/get.dart';
|
||||
// import 'package:permission_handler/permission_handler.dart';
|
||||
// import 'package:uco_mobile_poc_project/app/core/constants/app_contants.dart';
|
||||
// import 'package:uco_mobile_poc_project/app/core/constants/translation_keys.dart';
|
||||
// import 'package:uco_mobile_poc_project/app/core/dialogs/custom_loading.dart';
|
||||
// import 'package:uco_mobile_poc_project/app/custom_widgets/Fields/input_field.dart';
|
||||
// import 'package:uco_mobile_poc_project/app/custom_widgets/custom_toasty.dart';
|
||||
//
|
||||
// class ContactsScreenController extends GetxController {
|
||||
// static TextEditingController phoneController = TextEditingController();
|
||||
// Contact? selectedContact;
|
||||
//
|
||||
// List<Contact> contactsList = [];
|
||||
// RxList<Contact> filteredContacts = <Contact>[].obs;
|
||||
//
|
||||
// late InputField searchContacts;
|
||||
//
|
||||
// @override
|
||||
// void onInit() {
|
||||
// super.onInit();
|
||||
// _loadContacts();
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// onReady() {
|
||||
// super.onReady();
|
||||
// // searchContacts.controller?.addListener(() {
|
||||
// // if (searchContacts.getCustomText().isEmpty) {
|
||||
// // filteredContacts.assignAll(contactsList);
|
||||
// // } else {
|
||||
// // filteredContacts.value = contactsList.where((element) => element.name.first == searchContacts.getCustomText() || element.name.last == searchContacts.getCustomText()).toList();
|
||||
// // }
|
||||
// // });
|
||||
// }
|
||||
//
|
||||
// Future<void> _loadContacts() async {
|
||||
// /// Check if the app has permission to access contacts
|
||||
// var status = await Permission.contacts.status;
|
||||
// // showLoader();
|
||||
// if (status.isGranted) {
|
||||
// /// Permission is granted, load contacts
|
||||
// try {
|
||||
// contactsList = await FlutterContacts.getContacts(withProperties: true, withAccounts: true, withPhoto: true, sorted: true, withThumbnail: true);
|
||||
// filteredContacts.assignAll(contactsList);
|
||||
// hideLoader();
|
||||
// } catch (e) {
|
||||
// print('Error loading contacts: $e');
|
||||
// hideLoader();
|
||||
// }
|
||||
// } else {
|
||||
// /// Permission is not granted, request permission
|
||||
// await _requestPermissions();
|
||||
// hideLoader();
|
||||
// }
|
||||
// hideLoader();
|
||||
// }
|
||||
//
|
||||
// Future<void> _requestPermissions() async {
|
||||
// /// Request contacts permission
|
||||
// var status = await Permission.contacts.request();
|
||||
// if (!status.isGranted) {
|
||||
// Toasty.error(TranslationKeys.makeTranslation(TranslationKeys.textPermissionDenied));
|
||||
// } else {
|
||||
// /// Permission granted, load contacts
|
||||
// await _loadContacts();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /// Function to filter contacts based on search query
|
||||
// void filterContacts(String searchText) {
|
||||
// if (searchText.isEmpty) {
|
||||
// filteredContacts.assignAll(contactsList);
|
||||
// } else {
|
||||
// searchText = searchText.toLowerCase();
|
||||
// filteredContacts.assignAll(contactsList.where((contact) {
|
||||
// // Check if either name or phone number matches the search text
|
||||
// bool matchesName = contact.name.first.toLowerCase().contains(searchText) ||
|
||||
// (contact.name.last != null && contact.name.last!.toLowerCase().contains(searchText));
|
||||
//
|
||||
// bool matchesPhoneNumber = false;
|
||||
// for (var number in contact.phones) {
|
||||
// if (number.number.toLowerCase().contains(searchText)) {
|
||||
// matchesPhoneNumber = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return matchesName || matchesPhoneNumber;
|
||||
// }).toList());
|
||||
// }
|
||||
// }
|
||||
// /// Phone number pattern
|
||||
// String flattenPhoneNumber(String phoneStr) {
|
||||
// return phoneStr.replaceAllMapped(RegExp(r'^(\+)|\D'), (Match m) {
|
||||
// return m[0] == "+" ? "+" : "";
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// void handleContactSelection(Contact selectedContact) {
|
||||
// Get.back(result: {AppConstants.SELECTED_CONTACT: selectedContact});
|
||||
// }
|
||||
//
|
||||
// }
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_contacts/flutter_contacts.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import '../../../core/constants/app_contants.dart';
|
||||
import '../../../core/constants/translation_keys.dart';
|
||||
import '../../../core/dialogs/custom_loading.dart';
|
||||
import '../../../custom_widgets/Fields/input_field.dart';
|
||||
import '../../../custom_widgets/custom_toasty.dart';
|
||||
|
||||
|
||||
class ContactsScreenController extends GetxController {
|
||||
static TextEditingController phoneController = TextEditingController();
|
||||
Contact? selectedContact;
|
||||
|
||||
List<Contact> contactsList = [];
|
||||
RxList<Contact> filteredContacts = <Contact>[].obs;
|
||||
|
||||
late InputField searchContacts;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
_loadContacts();
|
||||
}
|
||||
|
||||
@override
|
||||
onReady() {
|
||||
super.onReady();
|
||||
searchContacts.controller?.addListener(() {
|
||||
if (searchContacts.getCustomText().isEmpty) {
|
||||
filteredContacts.assignAll(contactsList);
|
||||
} else {
|
||||
filteredContacts.value = contactsList.where((element) => element.name.first == searchContacts.getCustomText() || element.name.last == searchContacts.getCustomText()).toList();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _loadContacts() async {
|
||||
/// Check if the app has permission to access contacts
|
||||
var status = await Permission.contacts.status;
|
||||
showLoader();
|
||||
if (status.isGranted) {
|
||||
/// Permission is granted, load contacts
|
||||
try {
|
||||
contactsList = await FlutterContacts.getContacts(withProperties: true, withAccounts: true, withPhoto: true, sorted: true, withThumbnail: true);
|
||||
filteredContacts.assignAll(contactsList);
|
||||
hideLoader();
|
||||
} catch (e) {
|
||||
print('Error loading contacts: $e');
|
||||
hideLoader();
|
||||
}
|
||||
} else {
|
||||
/// Permission is not granted, request permission
|
||||
await _requestPermissions();
|
||||
hideLoader();
|
||||
}
|
||||
hideLoader();
|
||||
}
|
||||
|
||||
Future<void> _requestPermissions() async {
|
||||
/// Request contacts permission
|
||||
var status = await Permission.contacts.request();
|
||||
if (!status.isGranted) {
|
||||
Toasty.error(TranslationKeys.makeTranslation(TranslationKeys.textPermissionDenied));
|
||||
} else {
|
||||
/// Permission granted, load contacts
|
||||
await _loadContacts();
|
||||
}
|
||||
}
|
||||
|
||||
/// Function to filter contacts based on search query
|
||||
void filterContacts(String searchText) {
|
||||
if (searchText.isEmpty) {
|
||||
filteredContacts.assignAll(contactsList);
|
||||
} else {
|
||||
searchText = searchText.toLowerCase();
|
||||
filteredContacts.assignAll(contactsList.where((contact) {
|
||||
// Check if either name or phone number matches the search text
|
||||
bool matchesName = contact.name.first.toLowerCase().contains(searchText) ||
|
||||
(contact.name.last != null && contact.name.last!.toLowerCase().contains(searchText));
|
||||
|
||||
bool matchesPhoneNumber = false;
|
||||
for (var number in contact.phones) {
|
||||
if (number.number.toLowerCase().contains(searchText)) {
|
||||
matchesPhoneNumber = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return matchesName || matchesPhoneNumber;
|
||||
}).toList());
|
||||
}
|
||||
}
|
||||
/// Phone number pattern
|
||||
String flattenPhoneNumber(String phoneStr) {
|
||||
return phoneStr.replaceAllMapped(RegExp(r'^(\+)|\D'), (Match m) {
|
||||
return m[0] == "+" ? "+" : "";
|
||||
});
|
||||
}
|
||||
|
||||
void handleContactSelection(Contact selectedContact) {
|
||||
Get.back(result: {AppConstants.SELECTED_CONTACT: selectedContact});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,107 +1,106 @@
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:get/get.dart';
|
||||
// import 'package:uco_mobile_poc_project/app/core/constants/translation_keys.dart';
|
||||
// import 'package:uco_mobile_poc_project/app/custom_widgets/custom_no_record.dart';
|
||||
// import 'package:uco_mobile_poc_project/app/res/app_colors.dart';
|
||||
// import 'package:uco_mobile_poc_project/app/res/app_dimensions.dart';
|
||||
//
|
||||
// import '../../../custom_widgets/custom_app_bar.dart';
|
||||
// import '../controllers/contacts_screen_controller.dart';
|
||||
//
|
||||
// class ContactsScreenView extends GetView<ContactsScreenController> {
|
||||
// const ContactsScreenView({Key? key}) : super(key: key);
|
||||
//
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// String className = runtimeType.toString().split('.').last;
|
||||
// return Scaffold(
|
||||
// appBar: DashBoardAppBar(
|
||||
// title: TranslationKeys.makeTranslation("Contacts"),
|
||||
// onBackButtonPressed: () {
|
||||
// Get.back();
|
||||
// },
|
||||
// ),
|
||||
// body: Padding(
|
||||
// padding: EdgeInsets.symmetric(vertical: AppDimensions.screenVerticalPadding, horizontal: AppDimensions.screenHorizontalPadding),
|
||||
// child: Column(
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// children: [
|
||||
// TextField(
|
||||
// style: Theme.of(context).textTheme.bodyMedium?.copyWith(fontWeight: FontWeight.w400, fontSize: 12),
|
||||
// decoration: const InputDecoration(
|
||||
// suffixIconColor: AppColors.colorPrimary,
|
||||
// filled: true,
|
||||
// fillColor: AppColors.colorGrey200,
|
||||
// enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.all(Radius.circular(10.0)), borderSide: BorderSide(width: 1, color: Colors.transparent)),
|
||||
// border: OutlineInputBorder(borderRadius: BorderRadius.all(Radius.circular(10.0)), borderSide: BorderSide(width: 1, color: AppColors.colorGrey500)),
|
||||
// focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.all(Radius.circular(10.0)), borderSide: BorderSide(width: 1, style: BorderStyle.solid, color: Colors.transparent)),
|
||||
// hintText: 'Search contact number',
|
||||
// hintStyle: TextStyle(fontSize: 14, fontWeight: FontWeight.w400, color: AppColors.colorGrey500),
|
||||
// suffixIcon: Icon(Icons.search_rounded, size: 22),
|
||||
// ),
|
||||
// onChanged: (value) {
|
||||
// controller.filterContacts(value);
|
||||
// }),
|
||||
// const SizedBox(height: 20),
|
||||
// Text(TranslationKeys.makeTranslation("Contacts"), style: Theme.of(context).textTheme.bodyMedium),
|
||||
// const SizedBox(height: 10),
|
||||
// Obx(() {
|
||||
// return controller.filteredContacts.isEmpty
|
||||
// ? const Center(
|
||||
// child: CustomNoRecord(title: "No Record Found", description: "We couldn't find any activity at this moment"),
|
||||
// )
|
||||
// : Expanded(
|
||||
// flex: 2,
|
||||
// child: ListView.builder(
|
||||
// itemCount: controller.filteredContacts.length,
|
||||
// itemBuilder: (context, index) {
|
||||
// final contact = controller.filteredContacts[index];
|
||||
// final phoneNumber = contact.phones.isNotEmpty ? contact.phones[0].number : 'No phone number';
|
||||
// return ListTile(
|
||||
// onTap: () {
|
||||
// controller.handleContactSelection(contact);
|
||||
// },
|
||||
// title: Text(contact.displayName),
|
||||
// subtitle: Text(
|
||||
// phoneNumber,
|
||||
// style: Theme.of(context).textTheme.bodySmall,
|
||||
// ),
|
||||
// leading: CircleAvatar(
|
||||
// backgroundColor: AppColors.colorPrimary,
|
||||
// backgroundImage: contact.photo != null ? MemoryImage(contact.photo!) : null,
|
||||
// child: Text(
|
||||
// getInitials(contact.displayName),
|
||||
// style: Theme.of(context).textTheme.titleSmall?.copyWith(color: Colors.white),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
// }),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// String getInitials(String fullName) {
|
||||
// if (fullName.isEmpty) {
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
// // Split the full name into words
|
||||
// List<String> nameParts = fullName.trim().split(' ');
|
||||
//
|
||||
// // Check if there's at least a first and last name
|
||||
// if (nameParts.length < 2) {
|
||||
// return fullName.substring(0, 1).toUpperCase(); // Get first character
|
||||
// }
|
||||
//
|
||||
// // Get first characters of first and last name
|
||||
// String firstInitial = nameParts[0].substring(0, 1).toUpperCase();
|
||||
// String lastInitial = nameParts[nameParts.length - 1].substring(0, 1).toUpperCase();
|
||||
//
|
||||
// return firstInitial + lastInitial;
|
||||
// }
|
||||
// }
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../../core/constants/translation_keys.dart';
|
||||
import '../../../custom_widgets/custom_app_bar.dart';
|
||||
import '../../../custom_widgets/custom_no_record.dart';
|
||||
import '../../../res/app_colors.dart';
|
||||
import '../../../res/app_dimensions.dart';
|
||||
import '../controllers/contacts_screen_controller.dart';
|
||||
|
||||
class ContactsScreenView extends GetView<ContactsScreenController> {
|
||||
const ContactsScreenView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String className = runtimeType.toString().split('.').last;
|
||||
return Scaffold(
|
||||
appBar: DashBoardAppBar(
|
||||
title: TranslationKeys.makeTranslation("Contacts"),
|
||||
onBackButtonPressed: () {
|
||||
Get.back();
|
||||
},
|
||||
),
|
||||
body: Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: AppDimensions.screenVerticalPadding, horizontal: AppDimensions.screenHorizontalPadding),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TextField(
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(fontWeight: FontWeight.w400, fontSize: 12),
|
||||
decoration: const InputDecoration(
|
||||
suffixIconColor: AppColors.colorPrimary,
|
||||
filled: true,
|
||||
fillColor: AppColors.colorGrey200,
|
||||
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.all(Radius.circular(10.0)), borderSide: BorderSide(width: 1, color: Colors.transparent)),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.all(Radius.circular(10.0)), borderSide: BorderSide(width: 1, color: AppColors.colorGrey500)),
|
||||
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.all(Radius.circular(10.0)), borderSide: BorderSide(width: 1, style: BorderStyle.solid, color: Colors.transparent)),
|
||||
hintText: 'Search contact number',
|
||||
hintStyle: TextStyle(fontSize: 14, fontWeight: FontWeight.w400, color: AppColors.colorGrey500),
|
||||
suffixIcon: Icon(Icons.search_rounded, size: 22),
|
||||
),
|
||||
onChanged: (value) {
|
||||
controller.filterContacts(value);
|
||||
}),
|
||||
const SizedBox(height: 20),
|
||||
Text(TranslationKeys.makeTranslation("Contacts"), style: Theme.of(context).textTheme.bodyMedium),
|
||||
const SizedBox(height: 10),
|
||||
Obx(() {
|
||||
return controller.filteredContacts.isEmpty
|
||||
? const Center(
|
||||
child: CustomNoRecord(title: "No Record Found", description: "We couldn't find any activity at this moment"),
|
||||
)
|
||||
: Expanded(
|
||||
flex: 2,
|
||||
child: ListView.builder(
|
||||
itemCount: controller.filteredContacts.length,
|
||||
itemBuilder: (context, index) {
|
||||
final contact = controller.filteredContacts[index];
|
||||
final phoneNumber = contact.phones.isNotEmpty ? contact.phones[0].number : 'No phone number';
|
||||
return ListTile(
|
||||
onTap: () {
|
||||
controller.handleContactSelection(contact);
|
||||
},
|
||||
title: Text(contact.displayName),
|
||||
subtitle: Text(
|
||||
phoneNumber,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: AppColors.colorPrimary,
|
||||
backgroundImage: contact.photo != null ? MemoryImage(contact.photo!) : null,
|
||||
child: Text(
|
||||
getInitials(contact.displayName),
|
||||
style: Theme.of(context).textTheme.titleSmall?.copyWith(color: Colors.white),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String getInitials(String fullName) {
|
||||
if (fullName.isEmpty) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// Split the full name into words
|
||||
List<String> nameParts = fullName.trim().split(' ');
|
||||
|
||||
// Check if there's at least a first and last name
|
||||
if (nameParts.length < 2) {
|
||||
return fullName.substring(0, 1).toUpperCase(); // Get first character
|
||||
}
|
||||
|
||||
// Get first characters of first and last name
|
||||
String firstInitial = nameParts[0].substring(0, 1).toUpperCase();
|
||||
String lastInitial = nameParts[nameParts.length - 1].substring(0, 1).toUpperCase();
|
||||
|
||||
return firstInitial + lastInitial;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue