DVImage.memory constructor
DVImage.memory(})
Reads an image from a model's JSON.
A bare string is accepted and read as a network URL, because that is what
an existing API commonly sends for an image column.
An image from bytes in memory (PNG unless mimeType says otherwise).
Empty bytes are refused: they can only draw a broken image.
Implementation
factory DVImage.memory(
List<int> bytes, {
String mimeType = 'image/png',
String? alt,
int? width,
int? height,
}) {
if (bytes.isEmpty) {
throw ArgumentError.value(bytes, 'bytes', 'An image needs at least one byte.');
}
return DVImage(
source: DVImageSource.memory,
reference: 'data:$mimeType;base64,${base64Encode(bytes)}',
alt: alt,
width: width,
height: height,
);
}