Flutter NetworkImage vs cached_network_image - flutter

Flutter recommends to use cached_network_image here https://flutter.dev/docs/cookbook/images/cached-images. I used it and it worked fine. I tried NetworkImage and it worked, too.
I read from the doc that NetworkImage also caches the downloaded image locally. So what's the point in using cached_network_image instead of NetworkImage? Is there a comparison how their caching strategies differentiate from one another? Thanks!

The difference is significant and really helpful too...as you know fetching image from network takes time so cached network image provides you options for space holder to show when loading and error widget when can't load which are not there in NetworkImage. As a developer, you must be ready for every situation so that's the reason for recommending cached network images.
UPDATE:
ImageNetwork now has a loadingBuilder and errorbuilder parameters, so it too can now show a loading indicator similar to cached network image. But in CachedImageNetwork once the image is loaded it's cached in the system until the URL changes, which gives faster loading of the image every time and there are also many more features to explore please see official read me documents.
So still I prefer cachedNetworkImage until NetworkImage has similar features.
Hope you understand! Otherwise, let me know in the comments down below!

The difference is the cashed network image have a loading indicator when the image being fetched from the internet and show error icon if happen something error while fetching the image. While network image don't have this features. https://pub.dev/packages/cached_network_image

Related

Is there a way to display images from the internet immediately with zero delay?

My idea is to predownload them upon the first page or the page in question before the widgets are displayed, and then once they are downloaded, displaying the images will be as fast as displaying a Text widget for instance.
I have researched a lot based on Cached Network Images, Flutter Cache Manager and precache images, but all of them have a delay in loading the image.
The idea is that since it is finished downloading, it should display it immediately. And the downloading should happen in secret, before the page is loaded.
Any solutions?
cached_network_image support precache
https://github.com/Baseflow/flutter_cached_network_image/issues/646#issuecomment-905275798
and also
https://api.flutter.dev/flutter/widgets/precacheImage.html

How to make a transition between an asset image and an network image

How to make a transition between a local image and an image that comes from an internet server I would like the internet image to appear slowly.
I'm trying various things, but this ultimately worked the best, although I still can't smoothly transition.
I suggest you to check the cached_network_image package.
You can specify a placeholder widget which could be the local asset image, and the library will handle the loading and the animation for displaying the network image when it is ready.
Read the documentation for more customization.

How do I prevent Image.network from caching in between requests

How do you prevent Flutter's Image.network from caching?
I am trying to load random images from unsplash with it using one URL that returns a new Image on every query but it is only giving me the same one. Hence I think Image.network is caching.
I wrote this dartpad gist that illustrates the problem:
https://dartpad.dev/3ffc6011cedea9521997cf83bbfeb9c8
You'll notice it loads the same image three times but that link actually produces a different image on each hit.
Try and random number at the end of your request like:
Image.network("https://source.unsplash.com/collection/209138/400x100"),
Image.network("https://source.unsplash.com/collection/209138/400x100?2"),
Image.network("https://source.unsplash.com/collection/209138/400x100?4"),
You can randomise the numbers to make sure you always get new images

How to download and load downloads image in Custom UITableViewCell?

I get the text form the sever like this:
test_abc
http://www.xxx.a.jpg
test_aaa
http://www.xxx.b.jpg
test_ccc
I want to split the string to ["test_abc", "http://www.xxx.a.jpg", "test_aaa", "http://www.xxx.b.jpg", "test_ccc"] and then display them in a UITableViewCell,before the images will be downloaded, I used a LoadingIndicator as placeholder, when the images will be downloaded, display the images and modify the height of the cell to display the whole images.
Can someone help me do this?
Try looking into Three20
An open source library written by the guy who wrote the official "Facebook" app for iOS. Moreover, the code of the facebook app is based on that library.
You may use SDWebImage, and you don't have to worry about cache, etc..
Web Image
This library provides a category for UIImageVIew with support for remote images coming from the web.
It provides:
An UIImageView category adding web image and cache management to the Cocoa Touch framework
An asynchronous image downloader
An asynchronous memory + disk image caching with automatic cache expiration handling
A guarantee that the same URL won't be downloaded several times
A guarantee that bogus URLs won't be retried again and again
Performances!

Lazy loading thumbnail images

I am trying to lazily load a dynamic thumbnail view.
I have to put images in thumbnail view one by one and until images are not available I have to display temporary image like placeholder. Any guidelines please?
See the accepted answer in this thread. You wouldn't need the last-in first-out stack, but it shows how to load images asynchronously using grand central dispatch, which is quite straightforward. You don't need to think about complicated thread management. :)
You could go about like this -
Create a UIImageView with a default placeholder image.
Fetch your image in a background thread. You want to do it like this
because, fetching image in the main UI thread blocks it till the
image is fetched, which severely hampers UI responsiveness. There
are several libraries available which do this for you. They even
cache the images. SDWebImage is great!
See if you get a valid HTTP 200 response back i.e. a valid image. If yes, then replace the new image with placeholder image. Else let the placeholder image be.
Hope this helps...