Add Timeout Support for CachedNetworkImage Requests
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.
I think this is a duplicated issue of #465, and I've started to attempt to solve it.