Baseflow / flutter_cached_network_image

Download, cache and show images in a flutter app
https://baseflow.com
2.44k stars 654 forks source link

Expose ImageStreamListener in CachedNetworkImage/CachedNetworkImageProvider #774

Open kaiquegazola opened 2 years ago

kaiquegazola commented 2 years ago

🏗 Enhancement Proposal

Expose a ImageStreamListener parameter in CachedNetworkImage and CachedNetworkImageProvider and attach it in MultiImageStreamCompleter > ImageStreamCompleter listeners.

Pitch

Currently the package has an errorListener that is fires when an exception occurs while loading the image, but, without any information.

However, ImageStreamCompleter has a listener that provides more information: ImageStreamListener.

Also, by attaching an ImageStreamListener, we can handle uncatched exceptions as described in some issues (#726, #651, Firebase Crashlytics...) as can be seen in: https://github.com/flutter/flutter/blob/a7ba717b2fa1f2afa82131272902e60b5f3630a5/packages/flutter/lib/src/painting/image_stream.dart#L669-L672

/// If no error listeners (listeners with an [ImageStreamListener.onError]
/// specified) are attached, or if the handlers all rethrow the exception
/// verbatim (with `throw exception`), a [FlutterError] will be reported using
/// [FlutterError.reportError].

Platforms affected (mark all that apply)

atrope commented 2 years ago

777 should fix this.

atrope commented 2 years ago

@kaiquegazola you can try using in your pubspec like this:

  cached_network_image:
    git:
      url: https://github.com/SuaMusica/flutter_cached_network_image.git
      ref: feature/errorListener
      path: cached_network_image