Load .pdf file / custom file from flutter assets

后端 未结 1 1278
情话喂你
情话喂你 2021-01-14 22:10

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 f

相关标签:
1条回答
  • 2021-01-14 22:21

    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;
      }
    
    0 讨论(0)
提交回复
热议问题