checkFileUploadSize function

bool checkFileUploadSize(
  1. String path,
  2. String mediaType
)

Implementation

bool checkFileUploadSize(String path, String mediaType) {
  var file = File(path);
  int sizeInBytes = file.lengthSync();
  // debugPrint("file size --> $sizeInBytes");
  double sizeInMb = sizeInBytes / (1024 * 1024);
  // debugPrint("sizeInBytes $sizeInMb");

  // debugPrint(getFileSizeText(sizeInBytes.toString()));

  if (mediaType == Constants.mImage && sizeInMb <= Constants.maxImageFileSize) {
    return true;
  } else if (mediaType == Constants.mAudio &&
      sizeInMb <= Constants.maxAudioFileSize) {
    return true;
  } else if (mediaType == Constants.mVideo &&
      sizeInMb <= Constants.maxVideoFileSize) {
    return true;
  } else if (mediaType == Constants.mDocument &&
      sizeInMb <= Constants.maxDocFileSize) {
    return true;
  } else {
    return false;
  }
}