Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [0.6.4] - October 30, 2024

* Add null safety to example app
* Remove v1 Flutter Android embedding references

## [0.6.3] - September 21, 2021

* Android: added method getContactsByEmail (@fjbatresv)
Expand Down
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 30
namespace "flutter.plugins.contactsservice.contactsservice"

defaultConfig {
minSdkVersion 16
Expand Down
3 changes: 1 addition & 2 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="flutter.plugins.contactsservice.contactsservice">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<queries>
<intent>
<action android:name="android.accounts.AccountAuthenticator" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.Registrar;

import static android.app.Activity.RESULT_CANCELED;
import static android.provider.ContactsContract.CommonDataKinds;
Expand All @@ -66,16 +65,6 @@ public class ContactsServicePlugin implements MethodCallHandler, FlutterPlugin,
private final ExecutorService executor =
new ThreadPoolExecutor(0, 10, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1000));

private void initDelegateWithRegister(Registrar registrar) {
this.delegate = new ContactServiceDelegateOld(registrar);
}

public static void registerWith(Registrar registrar) {
ContactsServicePlugin instance = new ContactsServicePlugin();
instance.initInstance(registrar.messenger(), registrar.context());
instance.initDelegateWithRegister(registrar);
}

private void initInstance(BinaryMessenger messenger, Context context) {
methodChannel = new MethodChannel(messenger, "github.com/clovisnicolas/flutter_contacts");
methodChannel.setMethodCallHandler(this);
Expand Down Expand Up @@ -295,8 +284,9 @@ public boolean onActivityResult(int requestCode, int resultCode, Intent intent)
} else {
Log.e(LOG_TAG, "onActivityResult - cursor.moveToFirst() returns false");
finishWithResult(FORM_OPERATION_CANCELED);
}}else{return true;}
}
cursor.close();
}else{return true;}
return true;
}

Expand Down Expand Up @@ -374,24 +364,6 @@ private void openDeviceContactPicker(Result result, boolean localizedLabels) {
result.success(FORM_COULD_NOT_BE_OPEN);
}
}

private class ContactServiceDelegateOld extends BaseContactsServiceDelegate {
private final PluginRegistry.Registrar registrar;

ContactServiceDelegateOld(PluginRegistry.Registrar registrar) {
this.registrar = registrar;
registrar.addActivityResultListener(this);
}

@Override
void startIntent(Intent intent, int request) {
if (registrar.activity() != null) {
registrar.activity().startActivityForResult(intent, request);
} else {
registrar.context().startActivity(intent);
}
}
}

private class ContactServiceDelegate extends BaseContactsServiceDelegate {
private final Context context;
Expand Down
7 changes: 4 additions & 3 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 30
compileSdkVersion 34
namespace "flutter.plugins.contactsservice.contactsserviceexample"

lintOptions {
disable 'InvalidPackage'
Expand All @@ -24,7 +25,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "flutter.plugins.contactsservice.contactsserviceexample"
minSdkVersion 16
minSdkVersion flutter.minSdkVersion
targetSdkVersion 30
versionCode 1
versionName "1.0"
Expand All @@ -47,4 +48,4 @@ flutter {
dependencies {
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'
}
}
3 changes: 1 addition & 2 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="flutter.plugins.contactsservice.contactsserviceexample">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
Expand Down
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:8.6.0'
}
}

Expand All @@ -22,6 +22,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
4 changes: 2 additions & 2 deletions example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jun 23 08:50:38 CEST 2017
#Wed Oct 30 16:21:51 EDT 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
30 changes: 15 additions & 15 deletions example/lib/contacts_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ContactListPage extends StatefulWidget {
}

class _ContactListPageState extends State<ContactListPage> {
List<Contact> _contacts;
List<Contact> _contacts = [];

@override
void initState() {
Expand Down Expand Up @@ -40,7 +40,7 @@ class _ContactListPageState extends State<ContactListPage> {

void updateContact() async {
Contact ninja = _contacts
.firstWhere((contact) => contact.familyName.startsWith("Ninja"));
.firstWhere((contact) => contact.familyName?.startsWith("Ninja") == true);
ninja.avatar = null;
await ContactsService.updateContact(ninja);

Expand Down Expand Up @@ -90,7 +90,7 @@ class _ContactListPageState extends State<ContactListPage> {
? ListView.builder(
itemCount: _contacts?.length ?? 0,
itemBuilder: (BuildContext context, int index) {
Contact c = _contacts?.elementAt(index);
Contact c = _contacts.elementAt(index);
return ListTile(
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
Expand All @@ -100,8 +100,8 @@ class _ContactListPageState extends State<ContactListPage> {
contactOnDeviceHasBeenUpdated,
)));
},
leading: (c.avatar != null && c.avatar.length > 0)
? CircleAvatar(backgroundImage: MemoryImage(c.avatar))
leading: (c.avatar != null && c.avatar!.length > 0)
? CircleAvatar(backgroundImage: MemoryImage(c.avatar!))
: CircleAvatar(child: Text(c.initials())),
title: Text(c.displayName ?? ""),
);
Expand All @@ -126,14 +126,14 @@ class ContactDetailsPage extends StatelessWidget {
ContactDetailsPage(this._contact, {this.onContactDeviceSave});

final Contact _contact;
final Function(Contact) onContactDeviceSave;
final Function(Contact)? onContactDeviceSave;

_openExistingContactOnDevice(BuildContext context) async {
try {
var contact = await ContactsService.openExistingContact(_contact,
iOSLocalizedLabels: iOSLocalizedLabels);
if (onContactDeviceSave != null) {
onContactDeviceSave(contact);
onContactDeviceSave!(contact);
}
Navigator.of(context).pop();
} on FormOperationException catch (e) {
Expand Down Expand Up @@ -202,7 +202,7 @@ class ContactDetailsPage extends StatelessWidget {
ListTile(
title: Text("Birthday"),
trailing: Text(_contact.birthday != null
? DateFormat('dd-MM-yyyy').format(_contact.birthday)
? DateFormat('dd-MM-yyyy').format(_contact.birthday!)
: ""),
),
ListTile(
Expand All @@ -219,9 +219,9 @@ class ContactDetailsPage extends StatelessWidget {
? _contact.androidAccountType.toString()
: ""),
),
AddressesTile(_contact.postalAddresses),
ItemsTile("Phones", _contact.phones),
ItemsTile("Emails", _contact.emails)
AddressesTile(_contact.postalAddresses!),
ItemsTile("Phones", _contact.phones!),
ItemsTile("Emails", _contact.emails!)
],
),
),
Expand Down Expand Up @@ -323,7 +323,7 @@ class _AddContactPageState extends State<AddContactPage> {
actions: <Widget>[
TextButton(
onPressed: () {
_formKey.currentState.save();
_formKey.currentState?.save();
contact.postalAddresses = [address];
ContactsService.addContact(contact);
Navigator.of(context).pop();
Expand Down Expand Up @@ -407,7 +407,7 @@ class _AddContactPageState extends State<AddContactPage> {
}

class UpdateContactsPage extends StatefulWidget {
UpdateContactsPage({@required this.contact});
UpdateContactsPage({required this.contact});

final Contact contact;

Expand All @@ -416,7 +416,7 @@ class UpdateContactsPage extends StatefulWidget {
}

class _UpdateContactsPageState extends State<UpdateContactsPage> {
Contact contact;
late Contact contact;
PostalAddress address = PostalAddress(label: "Home");
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();

Expand All @@ -438,7 +438,7 @@ class _UpdateContactsPageState extends State<UpdateContactsPage> {
color: Colors.white,
),
onPressed: () async {
_formKey.currentState.save();
_formKey.currentState?.save();
contact.postalAddresses = [address];
await ContactsService.updateContact(contact);
Navigator.of(context).pushReplacement(
Expand Down
6 changes: 3 additions & 3 deletions example/lib/contacts_picker_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ContactPickerPage extends StatefulWidget {
}

class _ContactPickerPageState extends State<ContactPickerPage> {
Contact _contact;
Contact? _contact;

@override
void initState() {
Expand All @@ -18,7 +18,7 @@ class _ContactPickerPageState extends State<ContactPickerPage> {

Future<void> _pickContact() async {
try {
final Contact contact = await ContactsService.openDeviceContactPicker(
final Contact? contact = await ContactsService.openDeviceContactPicker(
iOSLocalizedLabels: iOSLocalizedLabels);
setState(() {
_contact = contact;
Expand All @@ -40,7 +40,7 @@ class _ContactPickerPageState extends State<ContactPickerPage> {
onPressed: _pickContact,
),
if (_contact != null)
Text('Contact selected: ${_contact.displayName}'),
Text('Contact selected: ${_contact!.displayName}'),
],
)),
);
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class _HomePageState extends State<HomePage> {
_askPermissions(null);
}

Future<void> _askPermissions(String routeName) async {
Future<void> _askPermissions(String? routeName) async {
PermissionStatus permissionStatus = await _getContactPermission();
if (permissionStatus == PermissionStatus.granted) {
if (routeName != null) {
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: contacts_service_example
description: Demonstrates how to use the contacts_service plugin.
environment:
sdk: '>=2.10.0 <3.0.0'
sdk: '>=2.12.0 <3.0.0'
dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
intl: ^0.17.0
intl: ^0.19.0

dev_dependencies:
flutter_test:
sdk: flutter

permission_handler: ^6.1.1
permission_handler: ^11.0.1
contacts_service:
path: ../

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: contacts_service
description: A Flutter plugin to retrieve and manage contacts on Android and iOS devices.
version: 0.6.3
version: 0.6.4
homepage: https://github.com/lukasgit/flutter_contacts
maintainer: Lukas Dickie (@lukasgit)

Expand Down