getDecodedBase64 static method
从缓存中获取已解码的数据;超预算数据仍返回,但不长期保留。
Implementation
static Uint8List? getDecodedBase64(String base64String) {
final entry = _touchBase64(base64String);
if (entry?.bytes != null) return entry!.bytes;
// 解码前确定缓存准入;不因此拒绝合法图片的解析或显示。
final canCache =
base64String.length * 2 + ((base64String.length + 3) ~/ 4) * 3 + 128 <=
_maxBase64CacheBytes;
try {
final bytes = base64.decode(base64String);
if (canCache) {
_cacheBase64(
base64String,
_ImageCacheEntry(
bytes: bytes,
size: entry?.size,
invalid: entry?.invalid ?? false,
),
);
}
return bytes;
} catch (_) {
return null;
}
}