getImage static method
Picker that close after selecting 1 image. Here are the different instance
of Future returned depending on outputType
:
-
ImageType.file return a html.File object of the selected image.
-
ImageType.bytes return a Uint8List of the selected image.
-
ImageType.widget return an Image.memory using the image's bytes.
html.File imgFile = await getImage(ImageType.file);
Uint8List imgBytes = await getImage(ImageType.bytes);
Image imgWidget = await getImage(ImageType.widget);
Implementation
static Future<dynamic> getImage({required ImageType outputType}) async {
if (!(outputType is ImageType)) {
throw ArgumentError(
'outputType has to be from Type: ImageType if you call getImage()');
}
final file = await ImagePickerWeb._pickFile('image');
if (file == null) return null;
switch (outputType) {
case ImageType.file:
return file;
case ImageType.bytes:
return file.asBytes();
case ImageType.widget:
return Image.memory(await file.asBytes(), semanticLabel: file.name);
}
}