如何在Flutter中显示一个Base64格式的PDF文件?

4

我有一个PDF的Base64内容,我需要在Flutter应用中显示它。

我正在尝试使用Dart的image、pdf和convert包,但是在image类中出现了错误,我不知道该如何显示这个图像。

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);

图片类错误信息为:尝试使用“as前缀”来替代其中一个导入指令,或者只允许一个导入指令使用该名称。

2个回答

1

谢谢,但是该文章显示了一个pdf文件的路径,而我只有Base64编码的内容。 - jhap
你不能把你的内容存储在文件中吗? - hawkbee
Future<String> _createFileFromString() async {
final encodedStr = "在此处放置base64编码的字符串"; Uint8List bytes = base64.decode(encodedStr); String dir = (await getApplicationDocumentsDirectory()).path; File file = File( "$dir/" + DateTime.now().millisecondsSinceEpoch.toString() + ".pdf"); await file.writeAsBytes(bytes); return file.path; }
- hawkbee
你从哪里获取这个方法?“类中未定义'getApplicationDocumentsDirectory'方法”。 - jhap
getApplicationDocumentsDirectory来自于path_provider包 https://pub.dev/packages/path_provider - hawkbee

0

这个错误意味着你导入了重复的Image模块。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接