Handle statusCode: 403 for Image.network
5,190
Solution 1
To handle exception you can use an Image.network with an errorBuilder
A builder function is called if an error occurs during image loading.
Image.network(myImageUrl,
errorBuilder: (BuildContext context, Object exception, StackTrace stackTrace) {
return Icon(Icons.do_not_disturb);
},
),
Solution 2
There is a PullRequest https://github.com/flutter/flutter/pull/18424 that is supposed to allow handling errors.
Author by
user2013047
Updated on December 06, 2022Comments
-
user2013047 over 1 year
Can you help resolve how to catch the exception when the image does not exist or image return code
HTTP request failed, statusCode: 403
dynamic _getImage() { try { return Image.network( "https://cdn.dribbble.com/users/1343501/screenshots/4789104/box_800_-601_2.gif", height: 96.0, width: 96.0, fit: BoxFit.cover); } catch (e) { return Icon(Icons.print); } }
-
user2013047 over 5 yearsCould you please elaborate how is that will help solve the Exception: HTTP request failed, statusCode: 403,
-
Günter Zöchbauer over 5 yearsI didn't have a chance yet to have a closer look.
-
Muhammed Refaat almost 2 yearsActually this merge request didn't help in handling this issue.