Last updated:
0 purchases
jingluo icloud storage
jingluo_icloud_storage #
flutter 云端存储
效果图 #
Getting started #
1. 项目配置 #
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刷新时触发 |
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.