Download a flutter generated file - flutter

I want to download(or save to downloads) a pdf file that is generated by flutter using flutter_html_to_pdf: ^0.5.2.
Which package or method should I use?
Thanks for the response.

Related

I want to view file like pdf,doc,pptx and etc in my flutter app using url and I don't want to store any file in device

I want to view file like pdf,doc,pptx and etc in my flutter app using url and I don't want to store any file in device
You can use the flutter_webview_plugin package to display files in your Flutter app without downloading or storing them on the device. Here is an example of how to use it to display PDF files:
Add the flutter_webview_plugin package to your pubspec.yaml file and run flutter pub get to install it.
Import the package in your Dart code:
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
Use the WebviewScaffold widget to display the PDF file:
WebviewScaffold(
url: 'https://example.com/path/to/file.pdf',
withZoom: true,
withLocalStorage: true,
);
The url parameter should point to the URL of the PDF file you want to display. The withZoom and withLocalStorage parameters are optional and control whether the user can zoom in and out of the file and whether any local storage is used for caching.
You can use the same approach to display other types of files, such as Microsoft Office documents and PowerPoint presentations, as long as the file is accessible via a URL.

Open generated file (Uint8list) in default application in Flutter

My application is generating excel and pdf reports. They are generated in Uint8list.
Is there a way to open such files in default application?
I tried open_file package, however, it requires a file path while my file is in memory.
same with url_launcher.
Also I tried saving the file then using open_file, but it doesn't work on web as file can't be saved.
I solved the issue by using printing.dat package. it has a PdfPreview that takes Uin8list and shows a preview with so many other options.

Flutter: Share fire directly (PDF)

It's possibile to share directly a Pdf file in flutter? I'm using Share_Plus plugin but it only support url or direct path.
My case:
Pdf uploaded on firebase
I retrive the URL
tried to use URI to file but I can't find the direct path to use with share_plus
The only solution is to save the file in the local storage of the phone and then retrieve di path and use with share_plus?
Thanks
You can use Firebase Storage. Files are url-referable from there.
Read all about it here: https://firebase.google.com/docs/storage

How to get local path of file in Flutter web

I'm using file_picker which give the path to the file in mobile, but in web the path is always null.
I read somewhere you can get the bytes of the file, but I couldn't understand how this it's done.
Right now I am trying to pick a video and showed on my web page with video_player, this method accepts a File.
So, is it possible to get the path of my video somehow and transformed to File?

How to open/find the file created by path_provider?

I'm a beginner at flutter and dart and had some issues with file handling using flutter.
I'm trying to store data locally in text files for my flutter application, and came across the standard tutorial on flutter's website which used path_provider and dart:io. It had instructions on getting the path and reading and writing to a file, however this didn't seem to work for files I added to the project. The only way to store to files was to first write using the inbuilt functions, then reading this newly created file. I can't add my own file and read it using flutter.
I also can't open the file created by flutter as I don't know where its stored. The path given by getApplicationDocumentsDirectory() returns the path /data/user/0/com.example.daily_challenges/app_flutter, and I don't know where to find this in my project.
In summary: How do I read a pre-existing file and how do I view the file created automatically by flutter.
Thanks :)
You can access the files from a physical device or simulator through Device File Explorer in Android Studio. Follow this guide
You won't be able to access getApplicationDocumentsDirectory().
If you are using android device, you can try to store it in getExternalStorageDirectory(). There's no equivalent in IOS though.
If you are running in a physical device. Open Device File Explorer in Android Studio and you can find the file under
data/data/your app package/app_flutter/fileName.txt
For example,
data/data/com.example.file_example/app_flutter/example.txt
And if you want to read the pre-existing file, you not need to anything specific, if you give the same file name, if not exist, it will create one, otherwise it will return the old one.
final File file = File(filePath);
file.writeAsStringSync('${text}', mode: FileMode.append);
For write, you consider using FileMode if you want to append text to the existing file. Or else by default overwrite will happen.
For read, you can consider this
final File file = File(filePath);
String text = await file.readAsString();
Just use Device File Explorer from Android Studio.
But the weird thing, path_provider gives you path like /data/user/0/your_app_id/..., but in fact all files are located in /data/data/your_app_id/..., as mentioned in previous answer.