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

3

6

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?

Pestana answered 11/3, 2021 at 20:41 Comment(0)
P
3

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();
Pestana answered 12/3, 2021 at 8:20 Comment(0)
M
1

gallery_saver has not been maintained for two years already. I am just using gal package instead.

import 'package:gal/gal.dart';

await Gal.putVideo(path);
Manila answered 26/6, 2023 at 11:13 Comment(0)
X
0

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.

Xanthe answered 15/1, 2022 at 7:59 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.