Skip to content

Commit

Permalink
re-enable profile contact creation for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
LGro committed May 23, 2024
1 parent 523d576 commit 4d93bee
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
6 changes: 3 additions & 3 deletions lib/data/repositories/contacts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class ContactsRepository {
_contactsStreamController.add(c);
}

await _updateFromSystemContacts();
await updateFromSystemContacts();
FlutterContacts.addListener(_systemContactsChangedCallback);

// Update the contacts from DHT and subscribe to future updates
Expand Down Expand Up @@ -322,7 +322,7 @@ class ContactsRepository {
// Delay to avoid system update coming in before other updates
await Future.delayed(const Duration(milliseconds: 100));
final oldProfileContact = _contacts[profileContactId];
await _updateFromSystemContacts();
await updateFromSystemContacts();
if (oldProfileContact != null &&
oldProfileContact != _contacts[profileContactId]) {
// Trigger update of share profiles and all that jazz
Expand Down Expand Up @@ -371,7 +371,7 @@ class ContactsRepository {

/// Update all system contacts in case they changed and add missing ones
// TODO: Test that there can be coagulate contacts with a system contact that isn't actually in the system
Future<void> _updateFromSystemContacts() async {
Future<void> updateFromSystemContacts() async {
// Try if permissions are granted
try {
var systemContacts = await systemContactsStorage.getContacts();
Expand Down
7 changes: 7 additions & 0 deletions lib/ui/locations/cubit.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion lib/ui/profile/cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ class ProfileCubit extends Cubit<ProfileState> {
Future<void> promptCreate() async {
if (await FlutterContacts.requestPermission()) {
emit(state.copyWith(status: ProfileStatus.create));
await setContact((await FlutterContacts.openExternalInsert())?.id);
final newContactId = (await FlutterContacts.openExternalInsert())?.id;
if (newContactId != null) {
// TODO: Can we be more trageted here, to only update the one contact id?
await contactsRepository.updateFromSystemContacts();
}
await setContact(newContactId);
}
}

Expand Down
5 changes: 4 additions & 1 deletion lib/ui/profile/cubit.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions lib/ui/profile/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -484,16 +484,18 @@ class ProfileViewState extends State<ProfileView> {
'profile or pick an existing contact that '
'contains your data from the address book.',
textScaler: TextScaler.linear(1.2))),
// TODO: Only display them when permissions granted, unless creation is possible in coagulate only
if (state.permissionsGranted) ...[
// Re-enable when fixed: https://github.com/QuisApp/flutter_contacts/issues/100
// TextButton(
// onPressed: context.read<ProfileCubit>().promptCreate,
// child: const Text('Create Profile',
// textScaler: TextScaler.linear(1.2))),
// Container(
// padding: const EdgeInsets.all(8),
// child: const Text('or', textScaler: TextScaler.linear(1.2))),
// Re-enable for Android when fixed: https://github.com/QuisApp/flutter_contacts/issues/100
if (Platform.isIOS)
TextButton(
onPressed: context.read<ProfileCubit>().promptCreate,
child: const Text('Create Profile',
textScaler: TextScaler.linear(1.2))),
if (Platform.isIOS)
Container(
padding: const EdgeInsets.all(8),
child:
const Text('or', textScaler: TextScaler.linear(1.2))),
TextButton(
onPressed: context.read<ProfileCubit>().promptPick,
child: const Text('Pick Contact as Profile',
Expand Down

0 comments on commit 4d93bee

Please sign in to comment.