showImagePickerBottomSheet function
Future<Object?>
showImagePickerBottomSheet({
- required bool cropImage,
- required bool useImagePicker,
- Color iconColor = Colors.grey,
- Color fontColor = Colors.black,
- EdgeInsetsGeometry padding = const EdgeInsets.symmetric(horizontal: marginX2),
- double modalFontSize = fontSizeL,
- File? image,
- CropAspectRatio? aspectRatio,
- String toolBarTitle = 'Crop Image',
- Color toolbarColor = Colors.grey,
- Color toolbarWidgetColor = Colors.white,
- bool hideBottomControls = true,
- bool lockAspectRatio = false,
- double? imageHeight,
- double? imageWidth,
- int? imageQuality,
- ResolutionPreset resolutionPreset = ResolutionPreset.medium,
- bool pickMultiple = false,
Implementation
Future<Object?> showImagePickerBottomSheet({
required bool cropImage,
required bool useImagePicker,
Color iconColor = Colors.grey,
Color fontColor = Colors.black,
EdgeInsetsGeometry padding = const EdgeInsets.symmetric(horizontal: marginX2),
double modalFontSize = fontSizeL,
File? image,
CropAspectRatio? aspectRatio,
String toolBarTitle = 'Crop Image',
Color toolbarColor = Colors.grey,
Color toolbarWidgetColor = Colors.white,
bool hideBottomControls = true,
bool lockAspectRatio = false,
double? imageHeight,
double? imageWidth,
int? imageQuality,
ResolutionPreset resolutionPreset = ResolutionPreset.medium,
bool pickMultiple = false,
}) async {
if (cropImage) {
File? result = await Get.bottomSheet(
Container(
color: Colors.white,
child: SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
contentPadding: padding,
leading: Icon(
Icons.camera_alt,
color: iconColor,
),
title: FXText(
'กล้อง',
size: modalFontSize,
weight: FontWeight.bold,
color: fontColor,
),
onTap: () async {
final cameras = await availableCameras();
File? file = await Get.to(
() => FXCameraPage(
cameras: cameras,
resolution: resolutionPreset,
),
);
image = await cameraCrop(
file!.path,
aspectRatio: aspectRatio,
toolbarTitle: toolBarTitle,
toolbarColor: toolbarColor,
toolbarWidgetColor: toolbarWidgetColor,
hideBottomControls: hideBottomControls,
lockAspectRatio: lockAspectRatio,
);
Get.back(result: image);
},
),
const Divider(),
ListTile(
contentPadding: padding,
leading: Icon(
Icons.photo,
color: iconColor,
),
title: FXText(
'แกลลอรี่',
size: modalFontSize,
weight: FontWeight.bold,
color: fontColor,
),
onTap: () async {
final file = await ImagePicker().pickImage(
source: ImageSource.gallery,
maxHeight: imageHeight,
maxWidth: imageWidth,
imageQuality: imageQuality,
);
image = await cameraCrop(
file!.path,
aspectRatio: aspectRatio,
toolbarTitle: toolBarTitle,
toolbarColor: toolbarColor,
toolbarWidgetColor: toolbarWidgetColor,
hideBottomControls: hideBottomControls,
lockAspectRatio: lockAspectRatio,
);
Get.back(result: image);
},
),
],
),
),
),
);
return result;
} else {
ImagePickerSource? result = await Get.bottomSheet(
Container(
color: Colors.white,
child: SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
contentPadding: padding,
leading: Icon(
Icons.camera_alt,
color: iconColor,
),
title: FXText(
'กล้อง',
size: modalFontSize,
weight: FontWeight.bold,
color: fontColor,
),
onTap: () async {
Get.back(result: ImagePickerSource.camera);
},
),
const Divider(),
ListTile(
contentPadding: padding,
leading: Icon(
Icons.photo,
color: iconColor,
),
title: FXText(
'แกลลอรี่',
size: modalFontSize,
weight: FontWeight.bold,
color: fontColor,
),
onTap: () async {
Get.back(result: ImagePickerSource.gallery);
},
),
],
),
),
),
);
File? pickedFile;
List<File> listPickedFile = [];
if (result == ImagePickerSource.camera) {
if (Platform.isAndroid) {
if (useImagePicker) {
pickedFile = await getImageFromCamera(
buttonColor: iconColor,
imageHeight: imageHeight,
imageWidth: imageWidth,
imageQuality: imageQuality,
);
if (pickMultiple) {
listPickedFile.add(pickedFile!);
}
} else {
final cameras = await availableCameras();
pickedFile = await Get.to(
() => FXCameraPage(
cameras: cameras,
resolution: resolutionPreset,
),
);
if (pickMultiple) {
listPickedFile.add(pickedFile!);
}
}
} else if (Platform.isIOS) {
pickedFile = await getImageFromCamera(
buttonColor: iconColor,
imageHeight: imageHeight,
imageWidth: imageWidth,
imageQuality: imageQuality,
);
if (pickMultiple) {
listPickedFile.add(pickedFile!);
}
}
} else if (result == ImagePickerSource.gallery) {
if (pickMultiple) {
listPickedFile = await getImageFromGallery(
buttonColor: iconColor,
imageHeight: imageHeight,
imageWidth: imageWidth,
imageQuality: imageQuality,
pickMultiple: pickMultiple,
);
} else {
pickedFile = await getImageFromGallery(
buttonColor: iconColor,
imageHeight: imageHeight,
imageWidth: imageWidth,
imageQuality: imageQuality,
pickMultiple: pickMultiple,
);
}
}
if (pickMultiple) {
return listPickedFile;
} else {
return pickedFile;
}
}
}