I have to fetch the image from a private server and have to display it. I am using the flutter Dio
library for API Integrations.
here I I call to API:
Future<GetFileResponse> getFileRequest(GetFileRequest getFileRequest) async {
try {
final response = await apiHelper.get(
"file/${getFileRequest.fileName}",
headers: {},
);
return GetFileResponse(response: response);
} on Exception catch (ex) {
throw ex;
}
}
Here GetFileResponse.response
type is var
Then I have a response like this:
�PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u00048\u0000\u0000\u00048\b\u0006\u0000\u0000\u0000�\u0010l�\u0000\u0000 \u0000IDATx\u0001��r%���Yd�t���s\u001d��1�'��s5[�\"�?�p\u0000�k��ջ[Rk��L\u0000\u0011\u001e\u001e�\u0000�k�/����?߿��\u001f�^��H�����ߌ(��`_\u0005��}j쳡{�-esЃ�p�v\f23J�� ..Continue...
Response: API Response on Postman
In my Screen I use this Logic to show Image:
var pictureBlob = state.getFileResponseEntity.response;
var image = base64.decode(pictureBlob);
CircleAvatar(
child:Image.memory(image),
),
But it executes an error when decoding this. It occurs this error:-
[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: FormatException: Invalid character (at character 1)
How can I solve this problem?