jingluo_icloud_storage 0.0.2 copy "jingluo_icloud_storage: ^0.0.2" to clipboard
jingluo_icloud_storage: ^0.0.2 copied to clipboard

PlatformiOSmacOS

Flutter plug-in for iCloud data synchronization on iOS and Mac OS

jingluo_icloud_storage #

flutter 云端存储

pub package

效果图 #

staggered_reorderable.gif

Getting started #

1. 项目配置 #

userdefaults.png

2. 使用 #

pubspec.yaml 添加如下:

dependencies:
  staggered_reorderable: <latest_version>
copied to clipboard

导入方式如下:

import 'package:jingluo_icloud_storage/jingluo_icloud_storage.dart';
copied to clipboard

使用方式如下:

  • 检查是否支持iCloud
var res = await JingluoIcloudStorage().isICloudEnabled();
copied to clipboard

返回结果如下

// 成功
{msg: Success, code: 0}

// 失败
{msg: error, code: -1}
copied to clipboard
  • 获取值

获取值时,如果拿不到key对应的value,则返回null。可选择获取指定类型的value,获取不到则为null

var res = await JingluoIcloudStorage().getValue(key: "localValue")
copied to clipboard

返回结果如下

// 成功
{msg: 138, code: 0}

// 失败
{msg: error, code: -1}
copied to clipboard

可选值type

enum JingluoIcloudStorageType {
  string,
  array,
  dictionary,
  data,
  long,
  double,
  bool,
  none,
}
copied to clipboard
  • 设置值
var res = await JingluoIcloudStorage().setValue(key: "count", value: 138);
copied to clipboard
// 成功
{msg: Success, code: 0}

// 失败
{msg: error, code: -1}
copied to clipboard
  • 删除值
var res = await JingluoIcloudStorage().deleteValue(key: "localValue")
copied to clipboard
// 成功
{msg: Success, code: 0}

// 失败
{msg: error, code: -1}
copied to clipboard
  • 监听值变化
JingluoIcloudStorage().registerEventListener(onEvent: (event) {
  if (event["key"] == JingluoIcloudStorageEventType.updateICloudStorage) {
    Map? map = event["payload"]["value"];
    if (map != null && map["count"] != null) {
      idx = map["count"];
    }
    setState(() {});
  }
});
copied to clipboard
// 成功
{payload: {code: 0, value: {count: 138}}, key: UPDATE_ICLOUD_STORAGE}
copied to clipboard

3. 常量 #

错误码 作用
0 成功
-1 参数错误
-2 iCloud未开启

| 事件Key | 作用 | |---------------------------|--------------------------| | UPDATE_ICLOUD_STORAGE | UserDefaults刷新时触发 |

2
likes
150
points
25
downloads

Publisher

unverified uploader

Weekly Downloads

2024.07.09 - 2025.01.21

Flutter plug-in for iCloud data synchronization on iOS and Mac OS

Repository (GitHub)

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on jingluo_icloud_storage