parse static method
Constructor that parses a Data URL s
defaultMimeType
if s
is invalid.
Implementation
static DataURLBase64? parse(String? s, {String? defaultMimeType}) {
if (s == null) return null;
s = s.trim();
if (s.isEmpty) return null;
if (!s.startsWith('data:')) return null;
var idx = s.indexOf(';');
if (idx < 5) return null;
String? mimeType = s.substring(5, idx);
var idx2 = s.indexOf(',');
if (idx2 < idx + 1) return null;
var encoding = s.substring(idx + 1, idx2).toLowerCase();
if (encoding != 'base64') return null;
var payload = s.substring(idx2 + 1);
mimeType = MimeType.parseAsString(mimeType, defaultMimeType);
return DataURLBase64(payload, mimeType);
}