putIfAbsent method

  1. @override
Uint8List putIfAbsent(
  1. Uint8List key,
  2. Uint8List value
)
override

Add a key, value pair to the underlying store if not key is in the underlying store. Returns the old value if key existed, otherwise value is returned.

putIfAbsent(utf8.encode('foo',utf8.encode('bar')
putIfAbsent(utf8.encode('foo',utf8.encode('baz') // returns 'bar'
get(utf8.encode('foo'); // returns 'bar'

Implementation

@override
Uint8List putIfAbsent(final Uint8List key, final Uint8List value) {
  _guardReadonly();
  final existing = get(key);
  if (existing != null) return existing;
  final transaction = begin();
  transaction.put(key, value);
  transaction.commit();
  return value;
}