So, I want to do a simple thing but for some reasons it is not working. I get a base64 string from the server which I need to convert to an image. When I put that retrieved in the websites like base64guru, it works. However I'm unable to do the same in my flutter app.
Here's what my code looks like:
final decodedBytes = base64Decode(base64String);
var file = File("userPdf.png");
file.writeAsBytesSync(decodedBytes);
return Image.file(file);
When this is executed, I get an error stating :
FileSystemException: Cannot open file, path = 'userPdf.png (OS Error: Read-only file system, errno = 30)
Any idea what I'm doing wrong and how I can do this ?? Any help would be appreciated.
CodePudding user response:
There is a simple way
Image.memory(base64Decode(base64String));
CodePudding user response:
Well, this got resolved when I wrapped SfPdfViewer.memory(bytes) inside a Container. Though, not sure why it wasn't working without a Container.
The whole solution:
Uint8List bytes = base64.decode(pdf);
return Container(
child: SfPdfViewer.memory(bytes),
);
Package used : syncfusion_flutter_pdfviewer