Skip to content

Commit

Permalink
Change Contact Package (#115)
Browse files Browse the repository at this point in the history
* change contacts package

* remove photo from contact fetch
  • Loading branch information
cp-sidhdhi-p authored Oct 9, 2024
1 parent d678289 commit 4d1c0c7
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 63 deletions.
12 changes: 6 additions & 6 deletions khelo/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -1457,14 +1457,14 @@ 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`)
- firebase_crashlytics (from `.symlinks/plugins/firebase_crashlytics/ios`)
- 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`)
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -1591,6 +1590,7 @@ SPEC CHECKSUMS:
FirebaseSharedSwift: d39c2ad64a11a8d936ce25a42b00df47078bb59c
FirebaseStorage: 9353f926690b2329957860abfcbc8b4074fe45e8
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_contacts: edb1c5ce76aa433e20e6cb14c615f4c0b66e0983
flutter_local_notifications: 4cde75091f6327eb8517fa068a0a5950212d2086
flutter_timezone: ffb07bdad3c6276af8dada0f11978d8a1f8a20bb
fluttertoast: e9a18c7be5413da53898f660530c56f35edfba9c
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -146,31 +146,32 @@ 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),
),
),
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);
}
Expand All @@ -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(),
),
),
),
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -40,7 +40,10 @@ class ContactSelectionViewNotifier
Future<void> 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);
Expand Down
24 changes: 8 additions & 16 deletions khelo/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion khelo/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4d1c0c7

Please sign in to comment.