Saving a Video into gallery using path_provider package - flutter

I have been Working on a small project where users can download WhatsApp status directly into their gallery. I made two tabs. one tab for WhatsApp Images and another for Videos. I could successfully download images into the gallery. now, I am facing a problem while downloading a Video into the gallery. I used path provider to download the video into the gallery. the Video gets downloaded in storage\emulated\0\android\data\com.JeevanCrasta.stikkers\files\videos\
I want to download those videos in the storage\emulated\0\Stikkr\videosdirectory. And those videos should be visible in the gallery. now those videos get downloaded in a different directory and are not visible in the gallary.
this is the code where videos get downloaded while the button is pressed :
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.teal,
child: Icon(Icons.download_sharp),
onPressed: () async {
_onLoading(true, "");
File originalVideoFile = File(widget.videoFile);
Directory directory = await getExternalStorageDirectory();
if (Directory("${directory.path.toString()}/Stikkr").existsSync()) {
Directory("${directory.path.toString()}/Stikkr")
.createSync(recursive: true);
}
String path = directory.path;
String curDate = DateTime.now().toString();
String newFileName = "$path/Stikkr/Videos/VIDEO-$curDate.mp4";
// print(newFileName);
await originalVideoFile.copy(newFileName);
_onLoading(false,
"If Video not available in gallary\n\nYou can find all videos at");
},
),

You can use package https://pub.dev/packages/gallery_saver
1 Saves images and videos from network, it has to contain http/https prefix.
2 Save temporary file to external storage
Both images and videos will be visible in Android Gallery and iOS Photos.
In your case, file has downloaded, so you can pass newFileName and use
GallerySaver.saveVideo(newFileName).then((String path) {
setState(() {
secondButtonText = 'video saved!';
});
});

Related

How to limit wechat asset picker to only JPG imges

In my app I want to allow users to pick multiple photos, I am usin for this Wechat Asset Picker, as I need to put a limit nfor number of photos can be selected.
afer that I need to compress these photos to reduce their siz befor uploadting to firestore.
I have two problems:
first, we chat asset picker package show all assets on the device, images, videos, etc. while I need to alow user only to upload images.
second, I am using Flutter Image Compress package for compressing, which works only with JPG.
Is there any better packages for my objective?
if not, my questions is how to limit wechat asset picker to only jpg images?
snapshots of code:
final List<myimagepicker.AssetEntity>? result =
await myimagepicker.AssetPicker.pickAssets(
context,
pickerConfig: const myimagepicker.AssetPickerConfig(
gridCount: 3,
maxAssets: 10,
pickerTheme: null,
themeColor: Color.fromARGB(255, 245, 91, 165),
pageSize: 30,
),
var result = await FlutterImageCompress.compressAndGetFile(
imageslist[i].absolute.path,
outPath,
quality: 50,
);
resultList = await AssetPicker.pickAssets(
context,
pickerConfig: const AssetPickerConfig(
maxAssets: 3,
requestType: RequestType.image, ✅
),
only jpg?
don't know
but only image?
you can set requestType.

ImagePicker never returning value flutter

I'm trying to prompt users of my app to upload photos. However, I'm have an issue. The function where I try to get the gallery image always returns null / never completes.
This i my code:
GestureDetector(
onTap: () async {
final image =
await ImagePicker().pickImage(source: ImageSource.gallery);
if (image != null) {
print(image.path);
print('exists');
}
},
It never prints 'exists' or image.path, I don't know whats wrong.
I have added this to info.plist
<key>NSCameraUsageDescription</key>
<string>For image upload and verification</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>For image upload and ID verification</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app uses the microphone for videos</string>
Package version: ^0.8.4
Would be really thankful for some input!

Flutter: save a generated PDF from preview page with a custom function

I'm using the pdf package (link to pub.dev page) to create documents inside my app.
How can I save the document from the preview page?
I know about the built-in print and share functions, but I need something else.
I need a function that does the following:
save the document to the device
upload it to Firebase Storage
delete the local file
I know how to do all of these steps, but I'm unable to access the Uint8List bytes of the pdf document that is being previewed... I've tried to add a PdfPreviewAction, but I still can't access the bytes of the document from it
all you have to do is call the save method in the Document() object
import "package:pdf/widgets.dart" as w;
final pdf = w.Document();
Future<Uint8List> getPDFData() async {
return await pdf.save();
}
you can do all the operations using the getPDFData() method
for example:
return PdfPreview(
build: (format) => getPdfData(),
actions: [
PdfPreviewAction(
icon: Icon(Icons.print),
onPressed: (context, fn, format) {
//if you call fn(format), you'll get Future<UInt8List>
}),
],
);

How do you download an image from the internet onto a file in Flutter?

I'm making a Flutter project where an image is displayed in listview and the user can share, favourite or download the image. I'm stuck on the downloading part. Is it possible to save an image file onto the phone's storage for offline use?
What I want to happen is I can create and write an image file
Future<String> get _localPath async {
final directory = await getApplicationDocumentsDirectory();
return directory.path;
}
Future<File> get _localFile async {
final path = await _localPath;
return File('$path/$title.txt');
}
// Write an image by obtaining an image through a URL
and then be able to access it through
Image.file('$path/$title.txt')

Playing videos with flutter web and firebase storage

I am trying to make a website in which the user can add videos and also see these videos. All of them are stored in firebase storage. This is how I store it
fb.StorageReference storageRef = fb.storage().ref('videos/$chapter)');
fb.UploadTaskSnapshot uploadTaskSnapshot = await storageRef.put(videoFile, fb.UploadMetadata(contentType: 'video/mp4')).future;
await uploadTaskSnapshot.ref.getDownloadURL().then((value){
videoUrl = value.toString();
});
snapshot.reference.collection("videos").add({
"chapter":chapter,
"class":grade,
"description":description,
"notes":notes,
"subject":subject,
"video":videoUrl,
"timestamp":DateTime.now().millisecondsSinceEpoch.toString()
});
And I play them using the normal video player plugin. Now the problem is when I store it, I get a url like
https://firebasestorage.googleapis.com/v0/b/studyme-me.appspot.com/o/videos%2Ff)?alt=media&token=ec4fea39-032b-438f-8122-f8e042c1c9c7
But the video player in flutter web requires a .mp4 or .wav or something like that file. What can I do that can either allow the video player to play these (I don't think its possible) or I can get the .mp4 file for this. Maybe I can use firebase storage to open this url and get it but I dont know how
Any suggestions would be appreciated
You can use the VideoPlayerController plugin to do that
VideoPlayerController controller = VideoPlayerController.network('your-video-url',);
//Play/Pause Video:
FloatingActionButton(
onPressed: () {
// Wrap the play or pause in a call to `setState`. This ensures the
// correct icon is shown
setState(() {
// If the video is playing, pause it.
if (_controller.value.isPlaying) {
_controller.pause();
} else {
// If the video is paused, play it.
_controller.play();
}
});
},
// Display the correct icon depending on the state of the player.
child: Icon(
_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
),
)
'''
more examples in the link above