setValue method

Future<bool> setValue(
  1. T value
)

Update the value and notify all listeners about the new value.

Returns true if the value was successfully set, otherwise returns false.

Implementation

Future<bool> setValue(T value) async {
  if (key == $$_getKeysKey) {
    /// This would not normally happen - it's a special case just for
    /// `getKeys()`.
    ///
    /// As `getKeys()` returns a `Set<String>` which represents the keys for
    /// currently stored values, its Preference key is a static, known value.
    /// This is "a bug, not a feature" - setting a value for `getKeys()` would
    /// not make sense.
    throw UnsupportedError(
      'setValue() not supported for Preference with a null key.',
    );
  }

  return _updateAndNotify(_adapter.setValue(_preferences, key, value));
}