【问题标题】:How can I show a pdf in base64 in flutter?如何在颤振中以base64显示pdf?
【发布时间】:2019-11-18 05:42:00
【问题描述】:

我有一个 base64 格式的 pdf 内容,我需要在颤振应用程序的容器中显示它。

我正在尝试使用图像、pdf 并从 dart 转换包,但图像类出现错误,我不知道如何显示图像。

List<int> pdfDataBytes = base64.decode(fileContent);
  Image img = decodeImage(pdfDataBytes);
  PdfImage image = PdfImage(
    pdf,
    image: img.data.buffer.asUint8List(),
    width: img.width,
    height: img.height);

这是图像类中的错误消息:尝试对其中一个导入指令使用“作为前缀”,或者对除一个导入之外的所有导入指令隐藏名称

【问题讨论】:

    标签: image pdf flutter dart


    【解决方案1】:

    此错误表示您有重复的图像导入。

    【讨论】:

      【解决方案2】:

      我没有测试它,但你有显示 pdf 的颤振包:flutter full pdf viewer 您可以找到here 使用此包与 pdf 资产的示例。

      【讨论】:

      • 谢谢,但是文章在路径中显示了一个pdf文件,我只有base64中的内容
      • 您不能将您的内容存储在文件中吗?
      • Future _createFileFromString() async { final encodedStr = "把base64编码的字符串放在这里"; Uint8List bytes = base64.decode(encodedStr); String dir = (await getApplicationDocumentsDirectory()).path;文件 file = File("$dir/" + DateTime.now().millisecondsSinceEpoch.toString() + ".pdf");等待文件.writeAsBytes(字节);返回文件.路径; }
      • 你从哪里得到的方法? “没有为类定义方法‘getApplicationDocumentsDirectory’”
      • getApplicationDocumentsDirectory 来自包 path_provider pub.dev/packages/path_provider
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-27
      • 1970-01-01
      • 2021-07-07
      • 1970-01-01
      • 2018-12-23
      • 2020-04-09
      • 2015-03-13
      相关资源
      最近更新 更多