conditionalCache static method
Future
conditionalCache({
- required dynamic key,
- required ValueType valueType,
- required dynamic actionIfNull,
- required dynamic actionIfNotNull,
Implementation
static Future conditionalCache(
{
// Cache key
required dynamic key,
// Cache value type [StringValue, BoolValue, IntValue, DoubleValue]
required ValueType valueType,
// Todo if cache is null
required dynamic actionIfNull,
// Todo if cache is not null
required dynamic actionIfNotNull}) async {
switch (valueType) {
case ValueType.StringValue:
{
dynamic cacheData = await ReadCache.getString(key: key);
if (cacheData == null) {
actionIfNull();
} else {
actionIfNotNull();
}
}
break;
case ValueType.BoolValue:
{
dynamic cacheData = await ReadCache.getBool(key: key);
if (cacheData == null) {
actionIfNull();
} else {
actionIfNotNull();
}
}
break;
case ValueType.IntValue:
{
dynamic cacheData = await ReadCache.getInt(key: key);
if (cacheData == null) {
actionIfNull();
} else {
actionIfNotNull();
}
}
break;
case ValueType.DoubleValue:
{
dynamic cacheData = await ReadCache.getDouble(key: key);
if (cacheData == null) {
actionIfNull();
} else {
actionIfNotNull();
}
}
break;
}
}