set method

  1. @override
Future<void> set(
  1. A? newValue
)
override

Sets the value of the Pod to newValue and calls notifyListeners if the value is different from the current value.

Implementation

@override
Future<void> set(A? newValue) async {
  if (_isEquatable(newValue)) {
    final v = await toValue(newValue);
    await shared_preferences.loadLibrary();
    _sharedPreferences ??=
        await shared_preferences.SharedPreferences.getInstance();
    switch (v) {
      case String s:
        await _sharedPreferences!.setString(key, s);
        break;
      case Iterable<String> list:
        await _sharedPreferences!.setStringList(key, list.toList());
        break;
      case bool b:
        await _sharedPreferences!.setBool(key, b);
        break;
      case int i:
        await _sharedPreferences!.setInt(key, i);
        break;
      case double d:
        await _sharedPreferences!.setDouble(key, d);
        break;
      default:
        await _sharedPreferences!.remove(key);
        return;
    }
    if (!isDisposed) {
      _value = newValue;
      notifyListeners();
    }
  }
}