errorBuilder property
A builder function that is called if an error occurs during image loading.
If this builder is not provided, any exceptions will be reported to FlutterError.onError. If it is provided, the caller should either handle the exception by providing a replacement widget, or rethrow the exception.
Important:
- If errorBuilder is null, will set the nullArtworkWidget and if is null will be used a icon(image_not_supported).
The following sample uses errorBuilder to show a '😢' in place of the image that fails to load, and prints the error to the console.
Widget build(BuildContext context) {
return DecoratedBox(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(),
borderRadius: BorderRadius.circular(20),
),
child: Image.network(
'https://example.does.not.exist/image.jpg',
errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
// Appropriate logging or analytics, e.g.
// myAnalytics.recordError(
// 'An error occurred loading "https://example.does.not.exist/image.jpg"',
// exception,
// stackTrace,
// );
return const Text('😢');
},
),
);
}
From flutter documentation
Implementation
final Widget Function(BuildContext, Object, StackTrace?)? errorBuilder;