How to save video recorded with camera package to gallery in Flutter?

Viewed 2186

I'm using the camera package to record videos in the app. How can I save the recorded video to gallery, if it saves to the app cache directory? I'm able to get the 'XFile' but I don't really know to how to go from there.

final file = await _cameraController.stopVideoRecording();
print(file.path); // /data/user/0/com.example/cache/REC804616628562956211.mp4

Also, should I then delete it from cache after copying the file? How can I do that?

2 Answers

I've managed to solve this myself. I used gallery_saver package to save the recorded video to gallery. Then I can delete the video file from cache using dart:io.

final video = await _cameraController.stopVideoRecording();
await GallerySaver.saveVideo(video.path);
File(video.path).deleteSync();

The above solution didn't quite work out for me. The recorded video got saved in my phone but not on my co-worker's phone. I would recommend the gallery_saver and image_picker packages. You can check out the example here: https://pub.dev/packages/gallery_saver

The video gets recorded and saved. With the camera plugin, I faced another issue where the video through the selfie camera got darkened.

Related