Flutter-保存文件对用户可见 [英] Flutter - Save file visible to the user
本文介绍了Flutter-保存文件对用户可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Flutter项目中,我创建了一个pdf文档.我可以将文档保存在应用程序的路径中. 但是用户无法访问它.另外,如何将文件保存到用户可以看到的另一个文件夹中?
In a Flutter project I create a pdf document. I can save the document in the path of the app. But the user has no access to it. Alternatively, how can I save the file to another folder where the user sees it?
import 'package:path_provider/path_provider.dart';
Future<void> savePdfDocument() async {
final PdfCreater generatedPdf = PdfCreater(document);
final List<int> generatedPdfDocument = generatedPdf.buildPdf();
final String dir = (await getApplicationDocumentsDirectory()).path;
final String path = '$dir/example.pdf';
final File file = File(path);
file.writeAsBytesSync(generatedPdfDocument);
}
推荐答案
在Android上使用 downloads_path_provider 它将文件保存在下载"中.
Use downloads_path_provider, on android it will save the file on Downloads.
对于IOS,您需要使用path_provider中的getApplicationDocumentsDirectory
并在info.plist
上添加权限以使该文件夹对用户可见:
for IOS, you need to use getApplicationDocumentsDirectory
from path_provider and add permissions on info.plist
to make the folder visible to the user:
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>UIFileSharingEnabled</key>
<true/>
这篇关于Flutter-保存文件对用户可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文