You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you would like to do it independently then you need to use the path_provider plugin to access the device's storage and then write the scanned image data (usually in a format like JPEG or PNG) to a file using the dart:io library's File class; essentially, you'll get the path where to save the file, create a File object at that location, and write the image data to it.
Following is the core part that you can do:
import 'dart:io';
import 'package:path_provider/path_provider.dart';
Future<void> saveDocument(List<int> imageData) async {
final directory = await getApplicationDocumentsDirectory();
final filePath = '${directory.path}/scanned_document_name.jpg';
final file = File(filePath);
await file.writeAsBytes(imageData);
}
When I checked the response of scannedDocument its a map and it doesn't have byte code to be saved as image, I think which is why I can't save it. Please correct me if am wrong. guide me to fix it or give a sample of code for scanned document to fetch image data.
@baburao455 - I haven't used it for the image, instead I am using an api to send the file with multipart (the same way we usually sends the file data). I used the bytes and created a file which is in PDF format. Here it is the function to do it:
// Gets the PDF from the assets
Future<File> getFileFromAssets(String assetPath) async {
final byteData = await rootBundle.load(assetPath);
final file = File(assetPath);
await file.writeAsBytes(byteData.buffer.asUint8List(), flush: true);
return file;
}
But you can try it for image along with the above given. Get the file bytes and then create it on the device.
I hope you will get some guidance from above combinations. Happy to get back from you :)
@baburao455 - I haven't used it for the image, instead I am using an api to send the file with multipart (the same way we usually sends the file data). I used the bytes and created a file which is in PDF format. Here it is the function to do it:
// Gets the PDF from the assets
Future<File> getFileFromAssets(String assetPath) async {
final byteData = await rootBundle.load(assetPath);
final file = File(assetPath);
await file.writeAsBytes(byteData.buffer.asUint8List(), flush: true);
return file;
}
But you can try it for image along with the above given. Get the file bytes and then create it on the device.
I hope you will get some guidance from above combinations. Happy to get back from you :)
@chuaz97 thank you so much for going extra mile, so in this case, I use your plug-in right.
Any good tutorial to create my own plug-in, very new to flutter but trying my best to learn. Let me know if you need a hand I can try.
I didn't fork your repo, you can access my source code here https://gitlab.com/dennis.turri/flutter_doc_scanner.git
Mine repo code is much simpler than yours, you can check the .kt file and .swift file to see what I made to get file's bytes
could anyone give me a "full" example of dealing with the scanned files? I'm preatty new in flutter. I'm in the point that I have my document scanned in variable scannedDocuments (like in the examples), so when I print it I see something like this:
could anyone give me a "full" example of dealing with the scanned files? I'm preatty new in flutter. I'm in the point that I have my document scanned in variable scannedDocuments (like in the examples), so when I print it I see something like this:
but when i try to create a file from this uri i'getting PathNotFoundException execption:
File file = File(uri);
how can I do something with this uri?
If you use my version posted in the comment above you can get the uint8list of the file, from there you can create a File
Only issue is that on iOS you can scan multiple pages but only the first will be saved
@chuaz97 thanks for your answer. Well, i dont really want to use a fork. So you trying to tell me, that is imposible in the "basic" version to obrain the file from this uri file:///data/user/0/com.example.dge_flutter/cache/mlkit_docscan_ui_client/33019206465400.pdf ?
@chuaz97 do you have any plans to create a PR in this repository from your edits on gitlab? Also your version on gitlab is missing a license, making it hard for anyone else to create a PR here from your changes.
@chuaz97 do you have any plans to create a PR in this repository from your edits on gitlab? Also your version on gitlab is missing a license, making it hard for anyone else to create a PR here from your changes.
I have no plans to create a PR. I've added a MIT License, you can do whatever you want with that code
Activity
pritamgudekar commentedon Feb 8, 2025
@baburao455 That would be a good option.
If you would like to do it independently then you need to use the path_provider plugin to access the device's storage and then write the scanned image data (usually in a format like JPEG or PNG) to a file using the dart:io library's File class; essentially, you'll get the path where to save the file, create a File object at that location, and write the image data to it.
Following is the core part that you can do:
This may help you to proceed further.
baburao455 commentedon Feb 8, 2025
hi @pritamgudekar ,
When I checked the response of scannedDocument its a map and it doesn't have byte code to be saved as image, I think which is why I can't save it. Please correct me if am wrong. guide me to fix it or give a sample of code for scanned document to fetch image data.
thanks again
chuaz97 commentedon Feb 8, 2025
Totally agree with @baburao455
We are unable to open that file.
It would be very useful to have the bytes of the scanned file, hoping it's possible
EDIT:
I've checked whole source code and generated a copy with the addition of getting file bytes. You can use it
flutter_doc_scanner:git:url: https://gitlab.com/dennis.turri/flutter_doc_scanner.gitand inside your app
Uint8List? pic = await FlutterDocScanner.scanDocument();pritamgudekar commentedon Feb 9, 2025
@baburao455 - I haven't used it for the image, instead I am using an api to send the file with multipart (the same way we usually sends the file data). I used the bytes and created a file which is in PDF format. Here it is the function to do it:
But you can try it for image along with the above given. Get the file bytes and then create it on the device.
I hope you will get some guidance from above combinations. Happy to get back from you :)
baburao455 commentedon Feb 9, 2025
@chuaz97 thank you so much for going extra mile, so in this case, I use your plug-in right.
Any good tutorial to create my own plug-in, very new to flutter but trying my best to learn. Let me know if you need a hand I can try.
baburao455 commentedon Feb 9, 2025
Thanks will check.
baburao455 commentedon Feb 9, 2025
@chuaz97 please also share fork access thanks
chuaz97 commentedon Feb 9, 2025
I didn't fork your repo, you can access my source code here https://gitlab.com/dennis.turri/flutter_doc_scanner.git
Mine repo code is much simpler than yours, you can check the .kt file and .swift file to see what I made to get file's bytes
aleksander237 commentedon Apr 11, 2025
Hello,
could anyone give me a "full" example of dealing with the scanned files? I'm preatty new in flutter. I'm in the point that I have my document scanned in variable scannedDocuments (like in the examples), so when I print it I see something like this:
{pdfUri: file:///data/user/0/com.example.dge_flutter/cache/mlkit_docscan_ui_client/33019206465400.pdf, pageCount: 1}but when i try to create a file from this uri i'getting PathNotFoundException execption:
File file = File(uri);how can I do something with this uri?
chuaz97 commentedon Apr 11, 2025
If you use my version posted in the comment above you can get the
uint8listof the file, from there you can create aFileOnly issue is that on iOS you can scan multiple pages but only the first will be saved
aleksander237 commentedon Apr 11, 2025
@chuaz97 thanks for your answer. Well, i dont really want to use a fork. So you trying to tell me, that is imposible in the "basic" version to obrain the file from this uri file:///data/user/0/com.example.dge_flutter/cache/mlkit_docscan_ui_client/33019206465400.pdf ?
aleksander237 commentedon Apr 11, 2025
Ok, stupid me. I was using code like this:
and I should use code like this
melewetwo commentedon Jun 11, 2025
@chuaz97 do you have any plans to create a PR in this repository from your edits on gitlab? Also your version on gitlab is missing a license, making it hard for anyone else to create a PR here from your changes.
chuaz97 commentedon Jun 11, 2025
I have no plans to create a PR. I've added a MIT License, you can do whatever you want with that code
shirsh94 commentedon Oct 31, 2025
If anyone has tested this @chuaz97 solution, please make a PR — I’d really appreciate your help!