-
Notifications
You must be signed in to change notification settings - Fork 30.6k
Image.network throws exceptions on HTTP errors #69125
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: debuggingDebugging, breakpoints, expression evaluationDebugging, breakpoints, expression evaluationa: imagesLoading, displaying, rendering imagesLoading, displaying, rendering imagesa: qualityA truly polished experienceA truly polished experiencefound in release: 1.22Found to occur in 1.22Found to occur in 1.22found in release: 1.24Found to occur in 1.24Found to occur in 1.24frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Description
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: debuggingDebugging, breakpoints, expression evaluationDebugging, breakpoints, expression evaluationa: imagesLoading, displaying, rendering imagesLoading, displaying, rendering imagesa: qualityA truly polished experienceA truly polished experiencefound in release: 1.22Found to occur in 1.22Found to occur in 1.22found in release: 1.24Found to occur in 1.24Found to occur in 1.24frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Type
Fields
Give feedbackNo fields configured for issues without a type.
As many developers have reported in the past, the
Image.networkconstructor throws an exception whenever an HTTP error occurs (be it a 4xx error, 5xx error, or a SocketException). This is done in spite of the fact that there are many ways in which the developer can provide fallbacks when such an error occurs; using the built-inerrorBuilderfor example, or by attaching anImageStreamListenerand implementing itsonErrorhandler.An HTTP error is not a failure of the code, and so should not throw an exception. Not when there are already hooks in place to allow the developer to handle the errors in a non-destructive manner. Throwing an exception is a major overkill and it completely breaks the app.
Use case
To understand the severity of this, try this:
ScrollViewthat loads manyImagewidgets at the same time (ala Pinterest). (You can start with the sample app from the errorBuilder docs -create --sample=widgets.Image.errorBuilder.1 mysample- and just modify it to insert multipleImage.networkwidgets into aScrollView.)What you'll end up having is an app that throws one exception after the other and a locked interface (E.g. no gesture responses on the scroll view).
Expected Behavior
An HTTP request should never throw an exception on failure. It should instead fail gracefully, providing
onErrorhooks, and allow the UI and logic to continue their execution.Proposed solution
onErrorhandler to theImage.networkconstructor.errorBuilderor anImageStreamListenerwith anonErrorhandler.