From 4d1c0c7524f3a8c3d4c7005e2d8d9974a7a6f710 Mon Sep 17 00:00:00 2001 From: sidhdhi canopas <122426509+cp-sidhdhi-p@users.noreply.github.com> Date: Wed, 9 Oct 2024 17:03:38 +0530 Subject: [PATCH] Change Contact Package (#115) * change contacts package * remove photo from contact fetch --- khelo/ios/Podfile.lock | 12 +-- .../contact_selection_screen.dart | 73 +++++++++---------- .../contact_selection_view_model.dart | 7 +- khelo/pubspec.lock | 24 ++---- khelo/pubspec.yaml | 2 +- 5 files changed, 55 insertions(+), 63 deletions(-) diff --git a/khelo/ios/Podfile.lock b/khelo/ios/Podfile.lock index 399ccf8b..a32d3ddf 100644 --- a/khelo/ios/Podfile.lock +++ b/khelo/ios/Podfile.lock @@ -1159,8 +1159,6 @@ PODS: - Firebase/Functions (= 11.2.0) - firebase_core - Flutter - - contacts_service (0.2.2): - - Flutter - device_info_plus (0.0.1): - Flutter - Firebase/Auth (11.2.0): @@ -1292,6 +1290,8 @@ PODS: - GoogleUtilities/Environment (~> 8.0) - GTMSessionFetcher/Core (~> 3.4) - Flutter (1.0.0) + - flutter_contacts (0.0.1): + - Flutter - flutter_local_notifications (0.0.1): - Flutter - flutter_timezone (0.0.1): @@ -1457,7 +1457,6 @@ PODS: DEPENDENCIES: - cloud_firestore (from `.symlinks/plugins/cloud_firestore/ios`) - cloud_functions (from `.symlinks/plugins/cloud_functions/ios`) - - contacts_service (from `.symlinks/plugins/contacts_service/ios`) - device_info_plus (from `.symlinks/plugins/device_info_plus/ios`) - firebase_auth (from `.symlinks/plugins/firebase_auth/ios`) - firebase_core (from `.symlinks/plugins/firebase_core/ios`) @@ -1465,6 +1464,7 @@ DEPENDENCIES: - firebase_messaging (from `.symlinks/plugins/firebase_messaging/ios`) - firebase_storage (from `.symlinks/plugins/firebase_storage/ios`) - Flutter (from `Flutter`) + - flutter_contacts (from `.symlinks/plugins/flutter_contacts/ios`) - flutter_local_notifications (from `.symlinks/plugins/flutter_local_notifications/ios`) - flutter_timezone (from `.symlinks/plugins/flutter_timezone/ios`) - fluttertoast (from `.symlinks/plugins/fluttertoast/ios`) @@ -1519,8 +1519,6 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/cloud_firestore/ios" cloud_functions: :path: ".symlinks/plugins/cloud_functions/ios" - contacts_service: - :path: ".symlinks/plugins/contacts_service/ios" device_info_plus: :path: ".symlinks/plugins/device_info_plus/ios" firebase_auth: @@ -1535,6 +1533,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/firebase_storage/ios" Flutter: :path: Flutter + flutter_contacts: + :path: ".symlinks/plugins/flutter_contacts/ios" flutter_local_notifications: :path: ".symlinks/plugins/flutter_local_notifications/ios" flutter_timezone: @@ -1565,7 +1565,6 @@ SPEC CHECKSUMS: BoringSSL-GRPC: ca6a8e5d04812fce8ffd6437810c2d46f925eaeb cloud_firestore: 5cb927f1a8c9d748d6fdbf16c6b267956cb82c53 cloud_functions: 071fdf2c9ae0932ea9eb8b7d8aef4b014112a8ab - contacts_service: 849e1f84281804c8bfbec1b4c3eedcb23c5d3eca device_info_plus: 97af1d7e84681a90d0693e63169a5d50e0839a0d Firebase: 98e6bf5278170668a7983e12971a66b2cd57fc8c firebase_auth: 0c77e299a8f2d1c74d1b1f6b78b3d4d802c19f47 @@ -1591,6 +1590,7 @@ SPEC CHECKSUMS: FirebaseSharedSwift: d39c2ad64a11a8d936ce25a42b00df47078bb59c FirebaseStorage: 9353f926690b2329957860abfcbc8b4074fe45e8 Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 + flutter_contacts: edb1c5ce76aa433e20e6cb14c615f4c0b66e0983 flutter_local_notifications: 4cde75091f6327eb8517fa068a0a5950212d2086 flutter_timezone: ffb07bdad3c6276af8dada0f11978d8a1f8a20bb fluttertoast: e9a18c7be5413da53898f660530c56f35edfba9c diff --git a/khelo/lib/ui/flow/team/add_team_member/contact_selection/contact_selection_screen.dart b/khelo/lib/ui/flow/team/add_team_member/contact_selection/contact_selection_screen.dart index 50f57b94..aa75aa40 100644 --- a/khelo/lib/ui/flow/team/add_team_member/contact_selection/contact_selection_screen.dart +++ b/khelo/lib/ui/flow/team/add_team_member/contact_selection/contact_selection_screen.dart @@ -1,8 +1,8 @@ import 'dart:typed_data'; import 'package:canopas_country_picker/canopas_country_picker.dart'; -import 'package:contacts_service/contacts_service.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_contacts/contact.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import 'package:khelo/components/app_page.dart'; @@ -146,12 +146,15 @@ class _ContactSelectionScreenState padding: const EdgeInsets.symmetric(horizontal: 16.0), child: Row( children: [ - _profileImageView(context, contact.avatar, - contact.displayName?.characters.firstOrNull), + _profileImageView( + context, + contact.thumbnail, + contact.displayName.characters.firstOrNull, + ), const SizedBox(width: 16), Expanded( child: Text( - contact.displayName ?? '', + contact.displayName, style: AppTextStyle.subtitle2 .copyWith(color: context.colorScheme.textPrimary), ), @@ -159,18 +162,16 @@ class _ContactSelectionScreenState const SizedBox(width: 4), SecondaryButton( context.l10n.common_add_title, - enabled: contact.phones != null && - contact.phones!.isNotEmpty && - !isActionInProgress, + enabled: contact.phones.isNotEmpty && !isActionInProgress, onPressed: () async { - if (contact.phones == null || contact.phones!.isEmpty) { + if (contact.phones.isEmpty) { return; } - if ((contact.phones?.length ?? 0) > 1) { + if (contact.phones.length > 1) { _showSelectNumberDialog(context, contact); } else { - final firstNumber = contact.phones?.first.value; - if (firstNumber != null && firstNumber.isNotEmpty) { + final firstNumber = contact.phones.first.number; + if (firstNumber.isNotEmpty) { showConfirmNumberSheet( context, contact.displayName, firstNumber); } @@ -193,31 +194,29 @@ class _ContactSelectionScreenState content: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, - children: contact.phones?.map((e) { - final showDivider = contact.phones?.lastOrNull != e; - if (e.value == null || e.value!.isEmpty) { - return const SizedBox(); - } - return OnTapScale( - onTap: () => context.pop(e.value), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - e.value ?? '', - style: AppTextStyle.subtitle3 - .copyWith(color: context.colorScheme.textPrimary), - ), - if (showDivider) - Divider( - height: 36, - color: context.colorScheme.outline, - ), - ], + children: contact.phones.map((e) { + final showDivider = contact.phones.lastOrNull != e; + if (e.number.isEmpty) return const SizedBox(); + + return OnTapScale( + onTap: () => context.pop(e.number), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + e.number, + style: AppTextStyle.subtitle3 + .copyWith(color: context.colorScheme.textPrimary), ), - ); - }).toList() ?? - [], + if (showDivider) + Divider( + height: 36, + color: context.colorScheme.outline, + ), + ], + ), + ); + }).toList(), ), ), ), @@ -261,9 +260,7 @@ class _ContactSelectionScreenState shape: BoxShape.circle, color: context.colorScheme.containerHigh, image: image != null && image.isNotEmpty - ? DecorationImage( - image: MemoryImage(image), - ) + ? DecorationImage(image: MemoryImage(image), fit: BoxFit.fill) : null), child: image != null && image.isNotEmpty ? null diff --git a/khelo/lib/ui/flow/team/add_team_member/contact_selection/contact_selection_view_model.dart b/khelo/lib/ui/flow/team/add_team_member/contact_selection/contact_selection_view_model.dart index f0c2e13d..bcebfbb4 100644 --- a/khelo/lib/ui/flow/team/add_team_member/contact_selection/contact_selection_view_model.dart +++ b/khelo/lib/ui/flow/team/add_team_member/contact_selection/contact_selection_view_model.dart @@ -1,10 +1,10 @@ import 'package:canopas_country_picker/canopas_country_picker.dart'; import 'package:collection/collection.dart'; -import 'package:contacts_service/contacts_service.dart'; import 'package:data/api/user/user_models.dart'; import 'package:data/service/device/device_service.dart'; import 'package:data/service/user/user_service.dart'; import 'package:flutter/cupertino.dart'; +import 'package:flutter_contacts/flutter_contacts.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:permission_handler/permission_handler.dart'; @@ -40,7 +40,10 @@ class ContactSelectionViewNotifier Future fetchContacts() async { try { state = state.copyWith(error: null, loading: true); - final fetchedContacts = await ContactsService.getContacts(); + final fetchedContacts = await FlutterContacts.getContacts( + withProperties: true, + withThumbnail: true, + ); state = state.copyWith(contacts: fetchedContacts, loading: false); } catch (e) { state = state.copyWith(loading: false, error: e); diff --git a/khelo/pubspec.lock b/khelo/pubspec.lock index a6d18ea1..18881291 100644 --- a/khelo/pubspec.lock +++ b/khelo/pubspec.lock @@ -278,14 +278,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.0" - contacts_service: - dependency: "direct main" - description: - name: contacts_service - sha256: f6d5ea33b31dfcdcd2e65d8abdc836502e04ddb0f66a96aa726fa9891ea9671e - url: "https://pub.dev" - source: hosted - version: "0.6.3" convert: dependency: transitive description: @@ -602,6 +594,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.4.1" + flutter_contacts: + dependency: "direct main" + description: + name: flutter_contacts + sha256: "388d32cd33f16640ee169570128c933b45f3259bddbfae7a100bb49e5ffea9ae" + url: "https://pub.dev" + source: hosted + version: "1.1.9+2" flutter_gen_core: dependency: transitive description: @@ -1257,14 +1257,6 @@ packages: url: "https://pub.dev" source: hosted version: "4.1.0" - quiver: - dependency: transitive - description: - name: quiver - sha256: ea0b925899e64ecdfbf9c7becb60d5b50e706ade44a85b2363be2a22d88117d2 - url: "https://pub.dev" - source: hosted - version: "3.2.2" riverpod: dependency: transitive description: diff --git a/khelo/pubspec.yaml b/khelo/pubspec.yaml index 9100f63e..8581828a 100644 --- a/khelo/pubspec.yaml +++ b/khelo/pubspec.yaml @@ -56,7 +56,7 @@ dependencies: qr_code_scanner: ^1.0.1 # contacts - contacts_service: ^0.6.3 + flutter_contacts: ^1.1.9+2 # picker canopas_country_picker: ^0.0.10