set method

  1. @override
Future<void> set(
  1. A newValue, {
  2. bool notifyImmediately = true,
})
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, {bool notifyImmediately = true}) async {
  final v = toValue(newValue);
  _sharedPreferences ??= await SharedPreferences.getInstance();
  switch (v) {
    case final String s:
      await _sharedPreferences!.setString(key, s);
    case final bool b:
      await _sharedPreferences!.setBool(key, b);
    case final int i:
      await _sharedPreferences!.setInt(key, i);
    case final double d:
      await _sharedPreferences!.setDouble(key, d);
    case final Iterable<String> list:
      await _sharedPreferences!.setStringList(key, list.toList());
    default:
      throw Err(
        'SharedPod only supports storing String, int, bool, double, and Iterable<String>. '
        'The provided value type is ${v.runtimeType}.',
      );
  }
  _set(newValue, notifyImmediately: notifyImmediately);
}