putIfAbsent method

  1. @override
V putIfAbsent(
  1. K key,
  2. V ifAbsent()
)
override

Look up the value of key, or add a new entry if it isn't there.

If key is present, returns its value. Otherwise, calls ifAbsent to get a new value, adds the key-value pair, and returns the new value. Notifies subscribers if a new entry is added.

Implementation

@override
V putIfAbsent(K key, V Function() ifAbsent) {
  if (peek.containsKey(key)) {
    return peek[key] as V;
  }
  final result = peek[key] = ifAbsent();
  notify(true);
  return result;
}