Flutter_cached_network_image: Add Support for Web

Created on 12 Dec 2019  路  20Comments  路  Source: Baseflow/flutter_cached_network_image

Please add support for web

web enhancement

Most helpful comment

Any ETAs? Can we at lease default showing the image without caching?

All 20 comments

me to

Any ETAs? Can we at lease default showing the image without caching?

No sorry, I can't give any ETA. You can make your own logic for if(web) -> normal NetworkImage for now.

Please add support for web

It's actually a bit more complicated than if (web) because if you attempt to access the Platform API then you'll crash your web version.

There is a kWeb constant you can use, but you have to be careful because simply importing a "bad" package can also crash your webapp. So you really need to use conditional imports to properly support Web and Android / iOS in the same app.

I just released a version that does this. It depends on CachedNetworkImage for Android / iOS, but falls back to NetworkImage if there are no headers, and using http to manually get the image if there are headers.

Feel free to let me know if you have any issues with it:
https://pub.dev/packages/websafe_network_image

@jpeiffer I just today also released a new version of CachedNetworkImageProvider that does about the same. It doesn't use caching for the web. It's in version 2.2.0.
https://pub.dev/packages/cached_network_image#-changelog-tab-

I'm currently working on a rewrite of the image library in such a way that is uses this ImageProvider instead of FileImage.

Hope to support for web, even not for cache image. Debug in browser is too difficult.

Version 2.3.0-beta should work on the web, can you test that?

@renefloor Oh, yes. It works in 2.3.0-beta, but sometimes it has some exception when hovered image.

Although this node is not marked as needing layout, its size is not set.
A RenderBox object must have an explicit size before it can be hit-tested. Make sure that the RenderBox in question sets its size during layout.

@Aoi-hosizora not sure if I understand it completely as I don't have much experience with flutter web, but I'll try to test it. I think it's good to make a separate issue.

@renefloor Thanks! I will test my app and make another issue if it is CachedNetworkImage's problem.

add pub.dev

@AngusPei what do you mean?

@renefloor

Add web support tags to pub.dev

image

I'm trying to find out how to do that. These tags are automatically added and this package depends on flutter_cache_manager which depends on sqflite, so this badge is not added.

@AngusPei do you know how to add the badge?

You can't manually, you would have to conditionally import the thing that is breaking compatibility. All exported members have to be web compatible to get a web badge. (The analysis shows exactly what is breaking compatibility)

@renefloor Is there any solution to cache Images on Web?

@BartusZak as far as I know Network.Image and CachedNetworkImage (using ImageRenderMethodForWeb.HtmlImage) should use the default browser cache for image files. I think that is the best you can get at the moment.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tolotrasamuel picture tolotrasamuel  路  6Comments

creativecreatorormaybenot picture creativecreatorormaybenot  路  4Comments

gunhansancar picture gunhansancar  路  3Comments

Gavin-1991 picture Gavin-1991  路  6Comments

anass-naoushi picture anass-naoushi  路  5Comments