Mar*_*ach 11 pdf storage store file flutter
在 Flutter 项目中,我创建了一个 pdf 文档。我可以将文档保存在应用程序的路径中。但用户无权访问它。或者,如何将文件保存到用户可以看到的另一个文件夹?
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);
}
Run Code Online (Sandbox Code Playgroud)
使用downloads_path_provider,在 android 上它会将文件保存在下载上。
对于 IOS,您需要使用getApplicationDocumentsDirectory
from path_provider 并添加权限info.plist
以使该文件夹对用户可见:
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>UIFileSharingEnabled</key>
<true/>
Run Code Online (Sandbox Code Playgroud)