stashValue method

Future<bool> stashValue(
  1. String key,
  2. dynamic value
)

Implementation

Future<bool> stashValue(String key, dynamic value) async {
  bool ok = true;
  try {
    // key must be supplied
    if (S.isNullOrEmpty(key)) return ok;

    if (value == null) {
      _stash.map.remove(key);
      _stash.upsert();
      Binding? binding = Binding.fromString('$key.value');
      if (binding != null) {
        stash.observables.remove(stash.getObservable(binding));
      }
      return ok;
    }

    // write application stash entry
    _stash.map[key] = value;

    // save to the hive
    await _stash.upsert();

    // set observable
    stash.setObservable(key, value);
  } catch (e) {
    // stash failure always returns true
    ok = true;
  }
  return ok;
}