2

I'm trying to dislpay image.memory but I'm getting an error as the following photo showing.

enter image description here

The bytes of image are the following. enter image description here

UPDATE -1-

Below you see my code enter image description here

enter image description here

UPDATE -2- The result if snpashot.data is null or not enter image description here

UPDATE -3- The changes that i did to get the bytes direct. But also getting error enter image description here

enter image description here

I can't explain it and I didn't find anythng solution for this error.

Thank you very much!

  • Post your code for Image.memory & variable which holds bytes. – Tirth Patel Feb 13 '21 at 15:44
  • 1
    I update it! Thank you! – Petros Pollakis Feb 13 '21 at 15:53
  • can you confirm `snapshot.data` passed in memory is null or not? – Tirth Patel Feb 13 '21 at 16:08
  • Yes, I updated. – Petros Pollakis Feb 13 '21 at 16:15
  • It seems bytes could be corrupted in `_getTripPictures`. Try rendering Image.memory with direct bytes output to confirm that once. – Tirth Patel Feb 13 '21 at 16:23
  • I tried and what I do is: I called the _getTripPictures to initState() and inside of the function I'm saving the base64Decode(valueImages[0]); to bytes and then the image.memory gets direct the byte variable but I'm getting a new error, i think it is because the widget builds first before the byte variable filled and the image.memory is null. Also if I use setState to fill the variable bytes with base64Decode(valueImages[0]); inside _getTripsPictures getting the same error plus this ---> Another exception was thrown: Exception: Invalid image data. SEE THE UPDATE -3- – Petros Pollakis Feb 13 '21 at 16:41
  • I meant, just pass the list directly without any async calls.. – Tirth Patel Feb 13 '21 at 16:50
  • How can I do that ? I should make async call to get the image bytes from my API node js – Petros Pollakis Feb 13 '21 at 17:22
  • Only for testing purposes to verify whether data is corrupted or not. Just pass the actual value you're getting in `Image.memory`. – Tirth Patel Feb 13 '21 at 17:28
  • I parse the bytes manually but I'm stll getting error of Exception: Invalid image data. What I can do now ? Thank you very much! – Petros Pollakis Feb 14 '21 at 16:23
  • I have the same problem. I think we have to encode image before pass to image memory. But I cannot find solutions – vannak Apr 26 '21 at 01:21

1 Answers1

0

It's possible that the base64 that you're trying to load in the Image widget is invalid. Try debugging, look for base64 image samples, load it in the Image widget, and see if it renders fine. You can also test encoding/decoding the image that you're using to see if it matches the decoded image using base64Decode()

Omatt
  • 8,564
  • 2
  • 42
  • 144