load method
Load the document.
After the document is loaded (or failed to load), the registered listeners (see addListener) are notified and then you can access document or error/stackTrace to check the result.
Of course, you can also await
the function and then call document to get PdfDocument.
The function can be called multiple times but the document is loaded only once unless forceReload
is true.
In that case, if the document requires password, the password is asked again.
The function returns a PdfDownloadReport if the document is loaded from remote source.
Implementation
Future<PdfDownloadReport?> load({bool forceReload = false}) async {
if (!forceReload && loadAttempted) {
return null;
}
return await synchronized(() async {
if (!forceReload && loadAttempted) return null;
final PdfDocument document;
PdfDownloadReport? report;
try {
final stopwatch = Stopwatch()..start();
document = await ref.loadDocument(_progress);
debugPrint('PdfDocument initial load: ${ref.sourceName} (${stopwatch.elapsedMilliseconds} ms)');
} catch (err, stackTrace) {
setError(err, stackTrace);
return report;
}
setDocument(document);
return report;
});
}