getOrBuildAndCacheIcon method
Gets an icon from the cache or builds and caches it if it doesn't exist.
key: A unique identifier for the icon.assetName: The path to the SVG asset.devicePixelRatio: The device's pixel ratio for correct scaling.size: The desired size of the icon.
Returns the icon data as a Uint8List.
Implementation
Future<Uint8List> getOrBuildAndCacheIcon({
required String key,
required String assetName,
required double devicePixelRatio,
Size? size = const Size(20, 20),
}) async {
// Find existing icon
CachedIcon? cachedIcon =
_cachedIconBox.query(CachedIcon_.key.equals(key)).build().findFirst();
if (cachedIcon != null) {
return Uint8List.fromList(cachedIcon.bytes);
}
// If not found, build and cache it
final Uint8List bytes = await _svgConverter(
assetName,
devicePixelRatio,
size,
);
final newCachedIcon = CachedIcon(key: key, bytes: bytes);
_cachedIconBox.put(newCachedIcon);
return bytes;
}