A Key Value Storage Flutter Plugin Sync multiple iOS and Mac

icloud_kv_storage

A Key Value Storage Flutter Plugin Sync multiple iOS & Mac Devices base on iCloud.

Snip20230607_1

Screen-2023-06-07-231010

Usage

NOTE: It is recommended to use real device testing for iOS devices as the iOS simulator may not synchronize in real-time. Mac devices can be compiled and tested directly. Only the same iCloud account needs to be logged in on different Apple devices to synchronize lightweight Key Value data.

  • FirstStep:

Enable your iOS Or Mac Project iCloud Key Value Services.

image

  • And Then Enjoy It.

Sample Code.

import 'package:icloud_kv_storage/icloud_kv_storage.dart';

var iCloudStorage = CKKVStorage();

Update A Key

void _incrementCounter() {
    setState(() {
      _counter++;
      iCloudStorage.writeString(key: key, value: _counter.toString());
    });
  }

Read A Key

iCloudStorage.getString('k_storage_count').then((value) {
      if (value != null) {
        setState(() {
          _counter = int.parse(value);
        });
      }
    });

Delete A Key

void _clearCounter() {
    setState(() {
      _counter = 0;
      iCloudStorage.delete(key);
    });
  }

Real Time Call Back Key Value Update on other devices

iCloudStorage.onCloudKitKVUpdateCallBack(
      onCallBack: (kvMap) {
        print('receive icloud_key_update map $kvMap');
        //if receive remove key will rec {flutter.k_storage_count: null}
        //if receive update key will rec {flutter.k_storage_count: 1}
        //because have prefix flutter. so need use my method to get real key.
        var key = iCloudStorage.getRealKey('k_storage_count');
        if (kvMap.containsKey(key)) {
          String? value = kvMap[key];
          setState(() {
            if (value != null) {
              _counter =
                int.parse(kvMap[iCloudStorage.getRealKey('k_storage_count')]);
            } else {
              _counter = 0;
            }
          });
        }
      },
    );

Release Log

0.0.1

Based on Apple CloudKit, lightweight Key value storage data can be synchronized between different Apple devices, such as iOS and Mac devices. For the time being, only String data can be synchronized.

Future

Currently, only String data is supported, and basic data types such as int and double will be added in the future

.gitignore

# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.packages
build/

.metadata

# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled.

version:
  revision: 62bd79521d8d007524e351747471ba66696fc2d4
  channel: stable

project_type: plugin

# Tracks metadata for the flutter migrate command
migration:
  platforms:
    - platform: root
      create_revision: 62bd79521d8d007524e351747471ba66696fc2d4
      base_revision: 62bd79521d8d007524e351747471ba66696fc2d4
    - platform: ios
      create_revision: 62bd79521d8d007524e351747471ba66696fc2d4
      base_revision: 62bd79521d8d007524e351747471ba66696fc2d4

  # User provided section

  # List of Local paths (relative to this file) that should be
  # ignored by the migrate tool.
  #
  # Files that are not part of the templates will be ignored by default.
  unmanaged_files:
    - 'lib/main.dart'
    - 'ios/Runner.xcodeproj/project.pbxproj'

Download details:

Author: JerryFans
Source: https://github.com/JerryFans/icloud_kv_storage

License: MIT license

#flutter #dart 

A Key Value Storage Flutter Plugin Sync multiple iOS and Mac
2.05 GEEK