conditionalCache static method

Future conditionalCache({
  1. required dynamic key,
  2. required ValueType valueType,
  3. required dynamic actionIfNull,
  4. 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;
  }
}