flutterflutter-html

How can I cache Network image received from HTML(format) API response? I want to cache it so I can display it even if there is no internet


I am trying to cache an image. The problem is that I receive it over an API whose response is in html format. I have simply used flutter_html package to render the response in my app. I save the response entirely in shared_preferences and show it to user. The problem now is that Everything else is just text so it is rendered when there is no internet but imageUrl can't be loaded obviously. I need help in maybe using flutter_html package or some kind of way to get it done.

My API response: "data":{ "description":" The world needs more people The world is underpopulated <img alt="" src="http://mayaalu.com/photos/1/Images_for_text_media/week-1.png" style="height:215px; width:238px" />" } I just display it with flutter_html:

Html( data: (data.description),),


Solution

  • use customImageRender using which you can use package like cached_network_image to cache the image so next time you are offline your image will be displayed.

    please see the documentation here https://pub.dev/packages/flutter_html