Open generated file (Uint8list) in default application in Flutter - 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.

Related

Is there a way to preview/open a file from a URL within the macCatalyst app without saving it in File system?

I'm trying to load/open/preview the files within the app but I don't want them to download and be saved in the file system to open them on MacCatalyst. I tried using QuickLook/QLPreviewController but it only works for files already stored in the File system.
I'm fairly new to MacCatalyst, any help is appreciated.

Flutter Web how to read and write file (xlsx,txt etc)

I am trying to read the two files first one is a text file and the second one is an excel file. I'm using flutter web 2.10 but can't find a way to read those files. I have tried this method but it doesn't work now To read and Write File in Flutter Web
Currently, I am kinda stuck with it. For now, I am reading the text file as a string and then parsing it, but it is not a good way to do it. So if you have any better way to read files in flutter web please do share.
Uint8List? bytes=result.files.first.bytes;
file=File.fromRawPath(bytes!);
file.readAsLines();
returnResult=file.toString();

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.

Imported packaged files ".key .numbers .pages" from iCloud using UIDocumentMenuViewController are not opening in UIWebView

Hi I am trying to display a packaged file say .key/.pages/.numbers file to user in a UIWebView but I cant. The keynote file was created using a Keynote app from my iPad recently. I imported that file to my app using UIDocumentMenuViewController from iCloud. I tried to look into the file attributes and it turn out that the file imported is actually a "directory" not single file. Inside, it has some contents. Can anybody tell me how to go from here?
I had the same problem. iWork files are zipped bundles but for some reason importing from iCloud unzips the contents first, whearas copying from the app directly via Open in ... from Number (or Pages or Keynote) works perfectly.
So what you need to do is test if the result of import is a directory, and if so zip the directory into a single file and keep the correct file extension (.number pages or .key).
This seems like a hack but it works and is best workaround I've been able to find
In Swift you can use SSZipArchive as an easy way to zip a directory

Access downloaded pdf file path in HTML5 file system and display it in webview

In my chrome app, I am using HTML5 file system to save the pdf files to sand box.Downloading is working fine.But how do i access that downloaded file path? I want to give that path as webview source.
The best way, if it works, would be to use a filesystem URL. To get this use FileEntry.toURL
These don't work on external files (i.e. files that come from chrome.fileSystem.chooseEntry and are outside the app's sandbox) but should work for files in the app's sandbox.
Note, I am referring to filesystem:// urls not file://urls, which won't work as Marc Rochkind has pointed out in his answer.
Disclaimer: I haven't tested this, but I believe it should work.
You need to get the contents of the PDF into a data URL. See my answer to this question:
Download external pdf files to chrome packaged app's file system