onCameraClick method

dynamic onCameraClick(
  1. BuildContext context
)

Implementation

onCameraClick(BuildContext context) async {
  if (!availableFeatures.value.isImageAttachmentAvailable.checkNull() &&
      !availableFeatures.value.isVideoAttachmentAvailable.checkNull()) {
    Helper.showFeatureUnavailable(context);
    return;
  }
  var cameraPermissionStatus = await AppPermission.checkAndRequestPermissions(
      permissions: [Permission.camera, Permission.microphone],
      permissionIcon: cameraPermission,
      permissionContent: AppConstants.cameraPermission,
      permissionPermanentlyDeniedContent:
          AppConstants.cameraCapturePermanentlyDeniedContent,
      context: context);
  if (cameraPermissionStatus) {
    if (context.mounted) {
      setOnGoingUserGone();
      Navigator.push(
              context, MaterialPageRoute(builder: (con) => CameraPickView()))
          .then((photo) {
        photo as XFile?;
        if (photo != null) {
          var file = PickedAssetModel(
              path: photo.path,
              type: !photo.name.endsWith(".mp4") ? "image" : "video",
              file: File(photo.path));
          Navigator.push(
              context,
              MaterialPageRoute(
                  builder: (con) => MediaPreviewView(
                        filePath: [file],
                        userName: profile.name.checkNull(),
                        profile: profile,
                        caption: messageController.text.trim(),
                        showAdd: false,
                        isFromGalleryPicker: false,
                      ))).then((value) => setOnGoingUserAvail());
        } else {
          setOnGoingUserAvail();
        }
      });
    } else {
      debugPrint("context is not mounted");
    }
  }
}