tryParse static method

UBase64Image? tryParse(
  1. String source
)

Decodes base64 image text and detects its kind; null when it is not base64.

Implementation

static UBase64Image? tryParse(String source) {
  final bool isDataUri = source.startsWith("data:");
  if (!isDataUri && (source.length < _minBarePayloadLength || source.contains("."))) return null;

  if (_cache.containsKey(source)) {
    final UBase64Image? hit = _cache.remove(source);
    _cache[source] = hit;
    return hit;
  }
  final UBase64Image? parsed = _parse(source, isDataUri);
  if (_cache.length >= _maxCacheEntries) _cache.remove(_cache.keys.first);
  _cache[source] = parsed;
  return parsed;
}