getUint8List method
Implementation
Future<Uint8List> getUint8List() async {
if (fallbackAssetPackage != null) {
final byteData = await rootBundle.load(fallbackAssetPackage != null
? 'packages/$fallbackAssetPackage/$fallbackAssetPath'
: fallbackAssetPath!);
final resizedImage = await _resizeImage(
byteData.buffer.asUint8List(),
width.toInt(),
height.toInt(),
);
return resizedImage;
} else {
final view = WidgetsBinding.instance.platformDispatcher.views.first;
final key = cacheKey == null
? null
: (cacheKey, width, height, view.devicePixelRatio);
final cached = key == null ? null : _bitmapCache.remove(key);
if (cached != null) {
_bitmapCache[key!] = cached; // most recently used goes last
return cached;
}
final Uint8List markerImage = await createImageFromWidget(
Directionality(
textDirection: TextDirection.ltr,
child: SizedBox(
width: width,
height: height,
child: widget,
),
),
waitToRender: renderDelay,
view: view,
);
// The capture is already `width x height` at a whole pixel ratio, which
// is what the resize would produce — and that resize decodes and
// re-encodes the PNG in Dart, on the UI thread.
final pixelRatio = view.devicePixelRatio;
final bitmap = pixelRatio == pixelRatio.roundToDouble()
? markerImage
: await _resizeImage(markerImage, width.toInt(), height.toInt());
if (key != null) {
_bitmapCache[key] = bitmap;
if (_bitmapCache.length > _bitmapCacheSize) {
_bitmapCache.remove(_bitmapCache.keys.first);
}
}
return bitmap;
}
}