showImagePickerBottomSheet function

Future<File?> showImagePickerBottomSheet()

Implementation

Future<File?> showImagePickerBottomSheet() async {
  ImagePickerSource? result = await Get.bottomSheet(
    Container(
      color: Colors.white,
      child: SafeArea(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            ListTile(
              contentPadding: const EdgeInsets.all(8.0),
              leading: const Icon(
                Icons.camera_alt,
                color: Colors.blue,
              ),
              title: const Text(
                'กล้อง',
                style: TextStyle(
                  fontSize: 20.0,
                  color: Colors.blue,
                ),
              ),
              onTap: () async {
                Get.back(result: ImagePickerSource.camera);
              },
            ),
            const Divider(),
            ListTile(
              contentPadding: const EdgeInsets.all(8.0),
              leading: const Icon(
                Icons.photo,
                color: Colors.blue,
              ),
              title: const Text(
                'แกลลอรี่',
                style: TextStyle(
                  fontSize: 20.0,
                  color: Colors.blue,
                ),
              ),
              onTap: () async {
                Get.back(result: ImagePickerSource.gallery);
              },
            ),
          ],
        ),
      ),
    ),
  );

  File? pickedFile;

  if (result == ImagePickerSource.camera) {
    if (Platform.isAndroid) {
      final cameras = await availableCameras();
      final camera = cameras.first;
      final imagePath = await Get.to(
        () => FXCameraPage(camera: camera),
      );

      pickedFile = File(imagePath);
    } else if (Platform.isIOS) {
      pickedFile = await getImageFromCamera();
    }
  } else if (result == ImagePickerSource.gallery) {
    pickedFile = await getImageFromGallery();
  }

  return pickedFile;
}