getOrCreateSymbol method

  1. @override
Future<SymbolImage?> getOrCreateSymbol(
  1. String? src,
  2. int width,
  3. int height
)

Retrieves a symbol from the cache or creates it if it doesn't exist.

The returned SymbolImage is a clone and must be disposed by the caller.

Implementation

@override
Future<SymbolImage?> getOrCreateSymbol(String? src, int width, int height) async {
  if (src == null || src.isEmpty) {
    // no image source defined
    return null;
  }
  String key = "$src-$width-$height";
  SymbolImage symbolImage = await _cache.getOrProduce(key, (_) async {
    return await _createSymbol(src, width, height);
  });
  return symbolImage.clone();
}