get static method

Future get(
  1. String key, {
  2. dynamic defaultValue,
  3. bool cache = true,
})

Gets the value of a setting with the specified key.

Parameters:

  • key: A unique key for the setting. It is case-insensitive and will be searched in lowercase.
  • defaultValue: The default value to return if the setting is not found. Defaults to null.
  • cache: Whether to cache the value in memory. Defaults to true.

Returns: The value of the setting or the default value if it is not found.

Implementation

static Future<dynamic> get(String key, {dynamic defaultValue, bool cache = true}) async {
  key = key.toLowerCase();

  if (cache && _cache.containsKey(key)) {
    return _cache[key];
  } else {
    final db = await DB.instance();
    final data = await db.kVs.where().keyEqualTo(key).findFirst();
    if (data != null) {
      final value = unserialize(data.value);
      _cache[key] = value;
      return value;
    } else {
      return defaultValue;
    }
  }
}