You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Image.network: errorBuilder with the failure cause, and a loading callback #115
I searched the existing feature requests and this is not a duplicate.
Framework or plugin?
Framework
Platform
Both
Use case
Image.network has one failure hook, errorWidget, "Only shown after a network error" (lib/src/widgets/image.dart). The cause (HTTP status, or the platform's error code) only goes to the console, as [DNImage] load failed … HTTP 404, and there is no callback when an image finishes loading. So the app can't tell a 404 from no network, can't log failures, can't retry, and can't fade an image in on its own terms once it's loaded.
(#62 added headers:, which we use; this is the next gap on the same widget.)
Proposal
As in Flutter, an errorBuilder that receives the error, and a loading / loaded callback:
Image.network(
url,
errorBuilder: (context, error, stackTrace) {
// error: e.g. NetworkImageLoadException(statusCode: 404, uri: url),// or an exception carrying the platform's error domain and code
log.warning('image failed', error);
returnconstPlaceholderArt();
},
loadingBuilder: (context, child, progress) =>
progress ==null? child :constShimmer(),
// or a simpler hook:
onLoad: () =>setState(() => loaded =true),
)
At minimum, an onError(Object error) callback with the status code or error code next to errorWidget would cover logging and retry.
Activity