set method

Future<bool> set(
  1. String key,
  2. dynamic value, {
  3. Duration? validFor,
})

Sets content for given key with Duration

Implementation

Future<bool> set(String key, dynamic value, {Duration? validFor}) async {
  _listeners.forEach((listener) {
    listener.keySet(key);
  });
  if (validFor != null) {
    _save(_withValidSuffix(key),
        DateTime.now().add(validFor).toIso8601String());
  } else {
    SharedPreferences prefs = await _getSharedPreferences();
    if (prefs.containsKey(_withValidSuffix(key))) {
      prefs.remove(_withValidSuffix(key));
    }
  }
  return _save(key, value);
}