cameraPicker static method
dynamic
cameraPicker({
- required FileData fileData,
- required dynamic onSelected(
- FileData fileData
- dynamic onCancel()?,
- bool crop = false,
- int? maxFileSizeInMb,
- bool cropOnlySquare = false,
- String cropperToolbarTitle = Files.cropperToolbarTitle,
- Color cropperToolbarColor = Files.cropperToolbarColor,
- Color cropperToolbarWidgetsColor = Files.cropperToolbarWidgetsColor,
function camera picker for take picture and save to temporary cache directory
Implementation
static cameraPicker(
{required FileData fileData,
required Function(FileData fileData) onSelected,
Function(String message, int messageCode)? onCancel,
bool crop = false,
int? maxFileSizeInMb,
bool cropOnlySquare = false,
String cropperToolbarTitle = Files.cropperToolbarTitle,
Color cropperToolbarColor = Files.cropperToolbarColor,
Color cropperToolbarWidgetsColor =
Files.cropperToolbarWidgetsColor}) async {
XFile? image = await ImagePicker().pickImage(source: ImageSource.camera);
if (image != null) {
String filePath = "";
if (crop) {
CroppedFile? croppedImage = await Files._imageCrop(
filePath: image.path,
cropOnlySquare: cropOnlySquare,
cropperToolbarTitle: cropperToolbarTitle,
cropperToolbarColor: cropperToolbarColor,
cropperToolbarWidgetsColor: cropperToolbarWidgetsColor);
if (croppedImage != null) {
filePath = croppedImage.path;
}
} else {
filePath = image.path;
}
if (!Files._isNullOREmpty(filePath)) {
if (maxFileSizeInMb != null &&
Files.mb(File(filePath).readAsBytesSync().lengthInBytes) >
maxFileSizeInMb) {
dev.log(
"[${Files._mcFPCForSize}] ${Files._fileMoreThanMB(maxFileSizeInMb)}");
if (onCancel != null) {
onCancel(
Files._fileMoreThanMB(maxFileSizeInMb), Files._mcFPCForSize);
}
return;
}
FileData fileData = FileData(
hasFile: true,
fileName: Files.getFileName(filePath),
filePath: filePath,
fileMimeType: Files.getMimeType(filePath),
path: filePath);
onSelected(fileData);
} else {
dev.log("[${Files._mcFPCForCancel}] ${Files._filePickCancel}");
if (onCancel != null) {
onCancel(Files._filePickCancel, Files._mcFPCForCancel);
}
return;
}
} else {
dev.log("[${Files._mcFPCForCancel}] ${Files._filePickCancel}");
if (onCancel != null) {
onCancel(Files._filePickCancel, Files._mcFPCForCancel);
}
return;
}
}