onErrorBuilder method Null safety

Widget? onErrorBuilder(
  1. BuildContext context,
  2. BuildMetadata meta,
  3. [dynamic error,
  4. dynamic data]
)

Builder for error widget if a complicated element failed to render.

See OnErrorBuilder.

Implementation

Widget? onErrorBuilder(
  BuildContext context,
  BuildMetadata meta, [
  dynamic error,
  dynamic data,
]) {
  final callback = _widget?.onErrorBuilder;
  if (callback != null) {
    final result = callback(context, meta.element, error);
    if (result != null) {
      return result;
    }
  }

  final image = data is ImageSource ? data.image : null;
  final semanticLabel = image?.alt ?? image?.title;
  final text = semanticLabel ?? '❌';
  return Text(text);
}