Baseflow / Baseflow/flutter_cached_network_image

errorWidget not working with most of network errors

Open
#932 5 comments 4 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
2.6k
Forks
731
Avg merge
3d 9h
Merged PRs (30d)
1

Description

## 🐛 Bug Report
When using the errorWidget property in Flutter to handle network errors, such as invalid image URLs or 403 errors, the errorWidget fails to display as expected. Instead, it throws exceptions, making it challenging to handle these specific network errors gracefully
### Expected behavior
The errorWidget property should gracefully handle network errors, such as invalid URLs or 403 errors, by displaying a custom widget specified by the developer. It should not throw exceptions that disrupt the app's functionality or user experience.
### Reproduction steps
Implement a Flutter widget that loads images from network URLs.
Provide an invalid image URL or simulate a 403 error response from the server.
Set up the errorWidget property to display a custom widget when network errors occur.
Attempt to load the image using the invalid URL or simulate the 403 error.
Observe that the errorWidget fails to display and instead throws exceptions.
### Configuration
CachedNetworkImage(
imageUrl: imageUrl ?? '',
fit: BoxFit.cover,
memCacheWidth: (250 * MediaQuery.of(context).devicePixelRatio).round(),
placeholder: (context, url) => Center(
child: SizedBox(
height: 3.h,
width: 6.w,
child: const CircularProgressIndicator(
color: AppColors.kWhiteColor,
strokeWidth: 1,
),
),
),
errorWidget: (context, url, error) {
try {
if (onLoadFailed != null) {
onLoadFailed!(index);
}
} catch (e) {
return Center(
child: SizedBox(
height: 3.h,
width: 6.w,
child: const CircularProgressIndicator(
color: AppColors.kWhiteColor,
strokeWidth: 1,
),
),
);
// Handle the error gracefully, you can log it or show a different widget
}
return Center(
child: SizedBox(
height: 3.h,
width: 6.w,
child: const CircularProgressIndicator(
color: AppColors.kWhiteColor,
strokeWidth: 1,
),
),
);
},
)
**Version:** 3.3.1

**Platform:**
Android

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.