pickImage static method
Implementation
static Future<dynamic> pickImage({
required BuildContext context,
bool isMultipleFile = false,
bool isFromFile = false,
bool isImgCropeble = false,
bool isOnlyImage = false,
bool isOnlyCamera = false,
}) async {
dynamic selectedImage;
await showModalBottomSheet(
context: context,
builder: (context) {
return Card(
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height / 4,
padding: const EdgeInsets.all(30),
child: Row(
children: [
if (!isMultipleFile && !isOnlyCamera)
_buildAction(
context: context,
icon: Icons.camera_alt_sharp,
label: "Camera",
onTap: () async {
selectedImage = await _pickImageFile(
context,
ImageSource.camera,
isMultipleFile,
isImgCropeble,
);
if (context.mounted) Navigator.pop(context); // Check if mounted
},
),
if (!isOnlyCamera)
_buildAction(
context: context,
icon: Icons.image,
label: "Gallery",
onTap: () async {
selectedImage = await _pickImageFile(
context,
ImageSource.gallery,
isMultipleFile,
isImgCropeble,
);
if (context.mounted) Navigator.pop(context); // Check if mounted
},
),
if (isFromFile)
_buildAction(
context: context,
icon: Icons.drive_file_move_rounded,
label: "Browse",
onTap: () async {
selectedImage =
await _pickFile(isMultipleFile, isOnlyImage);
if (context.mounted) Navigator.pop(context); // Check if mounted
},
),
],
),
),
);
},
);
return selectedImage;
}