将 base64 转换为图像 |不工作 |扑

Converting base64 to image | Not working | Flutter

所以,我想做一件简单的事情,但由于某些原因它不起作用。我从服务器获得一个 base64 字符串,我需要将其转换为图像。当我将检索到的内容放入 base64guru 等网站时,它就起作用了。但是我无法在我的 flutter 应用程序中执行相同的操作。

我的代码如下所示:

final decodedBytes = base64Decode(base64String);
var file = File("userPdf.png");
file.writeAsBytesSync(decodedBytes);
return Image.file(file);

执行此操作时,我收到一条错误消息:

FileSystemException: Cannot open file, path = 'userPdf.png (OS Error: Read-only file system, errno = 30)

知道我做错了什么以及我该怎么做吗??任何帮助将不胜感激。

有个简单的方法

Image.memory(base64Decode(base64String));

好吧,当我将 SfPdfViewer.memory(bytes) 包装在容器中时,这个问题得到了解决。虽然,不确定为什么没有容器它就不能工作。

整个解决方案:

Uint8List bytes = base64.decode(pdf);
return Container(
  child: SfPdfViewer.memory(bytes),
);

Package used : syncfusion_flutter_pdfviewer