flutter_cloud_kit 0.0.3 copy "flutter_cloud_kit: ^0.0.3" to clipboard
flutter_cloud_kit: ^0.0.3 copied to clipboard


Plugin for interaction with Apple CloudKit

flutter_cloud_kit #

A simple flutter plugin for interactions with Apple Cloud Kit API on iOS devices.

Currently, the following functionality is supported:

  • getAccountStatus - getting status of the user account;
  • saveRecord - saving records;
  • getRecord - getting records by key;
  • getRecordsByType - getting records by type;
  • deleteRecord - deleting record by key.

Usage #

Creating an instance of the FlutterCloudKit class #

FlutterCloudKit cloudKit = FlutterCloudKit(containerId: exampleContainerId);

containerId parameter is optional. When not provided, the default container will be used.

Getting account status #

CloudKitAccountStatus accountStatus = await cloudKit.getAccountStatus();

Saving a record #

await cloudKit.saveRecord(scope: CloudKitDatabaseScope.private, recordType: exampleRecordType, record: {'fieldName': 'fieldValue'}, recordName: 'RecordName');

Getting a record #

CloudKitRecord record = await cloudKit.getRecord(scope: CloudKitDatabaseScope.private, recordName: 'RecordName');

Getting records by type #

List<CloudKitRecord> records = await cloudKit.getRecordsByType(scope: CloudKitDatabaseScope.private, recordType: exampleRecordType);

Deleting a record #

await cloudKit.deleteRecord(scope: CloudKitDatabaseScope.private, recordName: 'RecordName');

Setup #

See Enabling CloudKit in Your App.

Basically, before you start using the plugin, you need to:

  • Add the iCloud Capability to Your Xcode Project;
  • Create a container you're going to use in Xcode;
  • Select the CloudKit checkbox;
  • Check the box next to the container name;

Also, in order to be able to retrieve records by type, you will need to add some indexes to the CloudKit database.

See Enable Querying for Your Record Type.

For every new record type you'll need to do the following:

  1. Create the first record of this type;
  2. Go to the CloudKit Console;
  3. Select your database;
  4. Go to the Indexes;
  5. Select your record type;
  6. Click Add Basic Index and create two indexes:
    • FIELD: recordName and Index Type: QUERYABLE (needed to fetch records);
    • FIELD: createdTimestamp and Index Type: SORTABLE (needed to sort them by creation time).
  7. Click Save Changes