Skip to content

Image.network: errorBuilder with the failure cause, and a loading callback #115

Backlog

Description

@tayormi

Select your plan

Standard - priority support

Confirmations

  • 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);
    return const PlaceholderArt();
  },
  loadingBuilder: (context, child, progress) =>
      progress == null ? child : const Shimmer(),
  // 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions