flutter_cached_network_image icon indicating copy to clipboard operation
flutter_cached_network_image copied to clipboard

Add Timeout Support for CachedNetworkImage Requests

Open nifra-s opened this issue 1 year ago • 1 comments

Hi,

First of all, thank you for this amazing package! It's very useful and widely appreciated in the Flutter community.

I would like to request a feature to add timeout support for image requests in the CachedNetworkImage widget. Problem:

Currently, there is no built-in way to configure a timeout for image requests. This can lead to scenarios where the widget keeps trying to load an image indefinitely, especially on slower networks or when the server is unresponsive. Proposed Solution:

It would be great to have a property like timeout in the CachedNetworkImage widget, where users can specify the maximum time (in milliseconds) the widget should wait for the image to load. If the timeout is exceeded, the widget could show an errorWidget or placeholder.

For example:

CachedNetworkImage(
  imageUrl: "https://example.com/image.jpg",
  timeout: Duration(seconds: 5), // Custom timeout
  errorWidget: (context, url, error) => Icon(Icons.error),
  placeholder: (context, url) => SkeletonLoader(), // Optional
);

Benefits:

  • Better user experience: Users will no longer experience indefinite loading times.
  • More control: Developers can adjust the timeout based on the app's needs.
  • Aligns with modern practices: Most networking libraries offer timeout configuration.

nifra-s avatar Jan 26 '25 22:01 nifra-s

I think this is a duplicated issue of #465, and I've started to attempt to solve it.

an920107 avatar Feb 19 '25 04:02 an920107