从Flutter资产加载.pdf文件/自定义文件 [英] Load .pdf file / custom file from flutter assets
本文介绍了从Flutter资产加载.pdf文件/自定义文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题是,在部署 flutter应用时,是否可以在诸如资产的应用资源中加载.pdf文件?我想使用以下方式显示PDF文件:
My question is if there is a way to load a .pdf file in app resources like assets when deploying flutter app ? I'd like to display a PDF file using this:
https://pub.dartlang.org/packages/flutter_full_pdf_viewer
但未从Internet加载;)
but without loading from internet ;)
推荐答案
将资产复制到临时文件中.
Copy the asset to a temporary file.
Future<File> copyAsset() async {
Directory tempDir = await getTemporaryDirectory();
String tempPath = tempDir.path;
File tempFile = File('$tempPath/copy.pdf');
ByteData bd = await rootBundle.load('assets/asset.pdf');
await tempFile.writeAsBytes(bd.buffer.asUint8List(), flush: true);
return tempFile;
}
这篇关于从Flutter资产加载.pdf文件/自定义文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文