scenePicture method

Picture scenePicture(
  1. Object key,
  2. Picture build()
)

A family scene's cached picture for key (value equality: e.g. a record of the spec, the size and the text-safe area), built by build on a miss; evicted pictures are disposed.

Implementation

ui.Picture scenePicture(Object key, ui.Picture Function() build) {
  final hit = _scenePictures.remove(key);
  if (hit != null) return _scenePictures[key] = hit;
  builds++;
  final picture = _scenePictures[key] = build();
  while (_scenePictures.length > capacity) {
    _scenePictures.remove(_scenePictures.keys.first)?.dispose();
  }
  return picture;
}