It is not safe to call the PDFDoc.text multiple times in succession, meaning to call it again before the previous call returns.
I's a pretty common scenario when an app may be processing more than one pdf file at a time.
If the program enters this function more than once before the previous call returns the app will crash.
I have tested this on a real Android device only and it crashes every single time if multiple pdfs are processed. Not sure how it behaves on iOS though.
There seems to be a workaround and it could be outlined as follows:
It is not safe to call the PDFDoc.text multiple times in succession, meaning to call it again before the previous call returns. I's a pretty common scenario when an app may be processing more than one pdf file at a time. If the program enters this function more than once before the previous call returns the app will crash. I have tested this on a real Android device only and it crashes every single time if multiple pdfs are processed. Not sure how it behaves on iOS though.
There seems to be a workaround and it could be outlined as follows:
class PDFReader{
static final _lock = Lock();
...
Future pdfToString(File aPdfFile) async {
...
String result;
PDFDoc doc = await PDFDoc.fromFile(aPdfFile);
await _lock.synchronized(() async {
result = await doc.text;
});
...
return result;
}
...
}
Where the Lock comes from https://pub.dev/packages/synchronized