组件的使用-Cache

[toc]

组件的使用-Cache

初始化:init

1
2
3
import 'package:flutter_cache_kit/flutter_cache_kit.dart';

LocalStorage.init();

Flutter 类型数据保存和获取方法:save/get

1
2
3
4
5
6
7
import 'package:flutter_cache_kit/flutter_cache_kit.dart';

// 保存方法:支持bool\int\double\String\List<String>
LocalStorage.save('test_string', string);

// 获取方法:支持bool\int\double\String\List<String>
String string = LocalStorage.get('test_string');

自定义的类的保存和获取方法:saveCustomBean\getCustomBean

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import 'package:flutter_cache_kit/flutter_cache_kit.dart';

// 保存
TSCustomBean customBean = TSCustomBean(
proxyId: '1001',
proxyIp: '192.168.1.1',
name: '代理',
);
LocalStorage.saveCustomBean(
'test_custom',
customBean,
itemToJson: (TSCustomBean bItem) {
return bItem.toJson();
},
);

// 获取
TSCustomBean customBean = LocalStorage.getCustomBean(
'test_custom',
fromJson: (bMap) {
return TSCustomBean.fromJson(bMap);
},
);

自定义的数组类的保存和获取方法:saveCustomBeans\getCustomBeans

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import 'package:flutter_cache_kit/flutter_cache_kit.dart';

// 保存
LocalStorage.saveCustomBeans(
'test_customBeans',
customBeans,
itemToJson: (TSCustomBean bItem) {
return bItem.toJson();
},
);

// 获取
List<TSCustomBean> customBeans = LocalStorage.getCustomBeans(
'test_customBeans',
fromJson: (bMap) {
return TSCustomBean.fromJson(bMap);
},
);