How you can save photos to the cellphone gallery on an IOS System in flutter?


‘I’m utilizing the saver_gallery package deal of Flutter to avoid wasting photos into my cellphone gallery on each IOS and android. I’m utilizing the image_picker package deal to take the picture utilizing digicam. Once I save the picture in my app, I can see it’s there within the gallery on an android cellphone however it’s failing on an IOS machine. Additionally if I reopen the app on the IOS machine neither can I see that picture on my app as nicely.’

Future checkAndRequestPermissions({required bool skipIfExists}) async 
  {
  if (!Platform.isAndroid && !Platform.isIOS) 
  {
    return false; // Solely Android and iOS platforms are supported
  }

  if (Platform.isAndroid) {
    closing deviceInfo = await DeviceInfoPlugin().androidInfo;
    closing sdkInt = deviceInfo.model.sdkInt;

    if (skipIfExists) {
      // Learn permission is required to verify if the file already exists
      return sdkInt >= 33
          ? await Permission.pictures.request().isGranted
          : await Permission.storage.request().isGranted;
    } else {
      // No learn permission required for Android SDK 29 and above
      return sdkInt >= 29 ? true : await Permission.storage.request().isGranted;
    }
  } else if (Platform.isIOS) {
    // iOS permission for saving photos to the gallery
    return skipIfExists
        ? await Permission.pictures.request().isGranted
        : await Permission.photosAddOnly.request().isGranted;
  }

  return false; // Unsupported platforms
}

Future saveImageToGallery(File imageFile, String imageName, {bool skipIfExists = false}) async{
  
  closing hasPermissions = await checkAndRequestPermissions(skipIfExists: skipIfExists);
  if(!hasPermissions){
    print("Permission Denied");
    return;
  }

  closing savedImage = await SaverGallery.saveFile(
    filePath: imageFile.path, 
    fileName: "$imageName.jpg", 
    androidRelativePath: "Photos/my_app",
    skipIfExists: skipIfExists);

   if(savedImage.isSuccess == true) {
    print(imageFile.path);
   } else{
    print("Failed");
   }
}

/* That is my operate to take a picture utilizing camersa*/

Future addImageFromCamera() async {
    closing pickedImage = await imagePick.pickImage(supply: ImageSource.digicam);
    return pickedImage != null ? File(pickedImage.path) : null;
  }

‘That is my code for a similar. I’m utilizing the very same code they’ve used within the pub.dev web page of the saver_gallery package deal, solely I’m utilizing a file as a substitute of picture bytes. I imagine the picture is saved briefly and it’s deleted later which is why I cant see it within the app as nicely. If anybody can please assist me with this it will be of nice assist. Thanks prematurely.’

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles