errorBuilder property

ImageErrorWidgetBuilder? errorBuilder
final

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.

{@tool dartpad --template=stateless_widget_material}

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('😢');
      },
    ),
  );
}

{@end-tool}

Implementation

// ignore: lines_longer_than_80_chars
///       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('😢');
///       },
///     ),
///   );
/// }
/// ```
/// {@end-tool}
final ImageErrorWidgetBuilder? errorBuilder;