Starlight Http Cached
存储 http 响应、String、int、double、bool、map、list 等数据的最简单方法。
功能
☑️ 设置缓存
☑️ 获取缓存
☑️ 删除缓存
☑️ 检查缓存
安装
将 starlight_http_cached 添加为 pubspec 文件中的依赖项。
starlight_http_cached:
git:
url: https://github.com/YeMyoAung/starlight_http_cached.git
用法
首先,您需要导入我们的包。
import 'package:starlight_http_cached/starlight_http_cached.dart';
初始化 StarlightHttpCached
要初始化 StarlightHttpCached,请调用 StarlightHttpCached 类上的实例方法
await StarlightHttpCached.instance;
设置缓存
import 'package:flutter/material.dart';
import 'package:starlight_http_cached/starlight_http_cached.dart';
Future<void> main() async {
///important
WidgetsFlutterBinding.ensureInitialized();
///important
await StarlightHttpCached.instance;
///setcached
StarlightHttpCached.setCached(
name: 'helloworld',
data: {
"Ye Myo Aung": "Ye Myo Aung",
},
);
}
获取缓存
import 'package:flutter/material.dart';
import 'package:starlight_http_cached/starlight_http_cached.dart';
Future<void> main() async {
///important
WidgetsFlutterBinding.ensureInitialized();
///important
await StarlightHttpCached.instance;
///get cached
print(
StarlightHttpCached.getCached(
name: 'helloworld',
),
);
}
删除缓存
import 'package:flutter/material.dart';
import 'package:starlight_http_cached/starlight_http_cached.dart';
Future<void> main() async {
///important
WidgetsFlutterBinding.ensureInitialized();
///important
await StarlightHttpCached.instance;
///delete cached
StarlightHttpCached.deleteCached(
name: 'helloworld',
);
}
检查缓存
import 'package:flutter/material.dart';
import 'package:starlight_http_cached/starlight_http_cached.dart';
Future<void> main() async {
///important
WidgetsFlutterBinding.ensureInitialized();
///important
await StarlightHttpCached.instance;
///check cached
print(
StarlightHttpCached.hasCached(name: 'helloworld'),
);
}
