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