replace method

void replace(
  1. E oldValue,
  2. E newValue
)

Replace the oldValue with newValue if found.

The listeners will be notified if oldValue is found.

Implementation

void replace(E oldValue, E newValue) {
  bool found = false;
  _values = Set<E>.of(_values.map<E>((E e) {
    if (e == oldValue) {
      found = true;
      if (_propagateNotification &&
          oldValue != null &&
          oldValue is ChangeNotifier) {
        oldValue.removeListener(_propagate);
      }
      if (_propagateNotification &&
          newValue != null &&
          newValue is ChangeNotifier) {
        newValue.addListener(_propagate);
      }
      return newValue;
    } else {
      return e;
    }
  }));

  if (found) notifyListeners();
}