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

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();

Related

Dealing with pdf files

I am implementing an application which its main idea is reading books using it.
the pdf files are on my server and I want the user to read the book without saving it on their device.
I thought about streaming the pdf file or embedding it. but it has some difficulties.
So, what is the best solution for this issue?
I am using Django-Rest-framework and Flutter
i think you have to use list of this packages for reading pdf files into flutter.
https://pub.dev/packages/syncfusion_flutter_pdf
https://pub.dev/packages/syncfusion_flutter_pdfviewer

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.

How to load csv from url and display as listview flutter

I am new to flutter and I found load csv from local and display as listview but I want to load from url and display. How can I do that?
A .csv from a remote source will probably have the content type of text/csv.
You should be able to call the url using a library (https://pub.dev/packages/http is a good choice, although I hear good things about Dio and probably a few others I haven't come across), get the data (e.g. as a http.Response), parse the response into some sort of model and then display it within the list view. Ideally the differences between displaying data from a local and remote source would be minimal - just where the data is coming from. This means you should be able to reuse the code you've written to load the data from a local source.
Without more information its hard to help. There's a good tutorial on building out Flutter apps using the Clean architecture at https://resocoder.com/category/tutorials/flutter/tdd-clean-architecture/. The difference will be that the Response data will be csv rather than JSON, so you'll need to sub in what you've done for the local loading.

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.

getting file information without uploading using scala

Can we get file information such as filesize, path of a file(even a large one) without actually uploading it onto the server using scala? PS. I know it can be done using Javascript, but I am searching for another way.