Reputation: 15
I am new to flutter and my college project require to save VCF file to contacts.
So i am trying to find a way to import my VCF file into my phone contacts. I used vcard_maintained https://pub.dev/packages/vcard_maintained to create the vcf file. can please tell me how i can lauch the phone contact from my flutter app and pass the data to it.
The Function that create the VCF:
save: () {
var vCard = VCard();
vCard.firstName = testingdatalist[index].displayname!;
vCard.jobTitle = testingdatalist[index].jobtitle!;
vCard.workPhone = testingdatalist[index].phonenumber1!;
vCard.note = testingdatalist[index].about!;
vCard.email = testingdatalist[index].email!;
vCard.saveToFile('./contact.vcf');
}
Upvotes: 0
Views: 2461
Reputation: 420
you can use flutter_contacts package. you can simply create a Contact
object from .vcf
file content and insert it!
import 'package:flutter_contacts/flutter_contacts.dart';
// Import contact from vCard
Contact contact = Contact.fromVCard('BEGIN:VCARD\n'
'VERSION:3.0\n'
'N:;Joe;;;\n'
'TEL;TYPE=HOME:123456\n'
'END:VCARD');
contact.insert();
p.s: in order to create contacts you need to add READ and WRITE permissions to your application. for that, Add the following key/value pair to your app's Info.plist (for iOS):
<plist version="1.0">
<dict>
...
<key>NSContactsUsageDescription</key>
<string>Reason we need access to the contact list</string>
</dict>
</plist>
Add the following tags to your app's AndroidManifest.xml (for Android):
<manifest xmlns:android="http://schemas.android.com/apk/res/android" ...>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<application ...>
...
Upvotes: 0