errorDisplayWidget static method

Widget errorDisplayWidget(
  1. FlutterErrorDetails details, {
  2. ParagraphStyle? paragraphStyle,
  3. TextStyle? textStyle,
  4. EdgeInsets? padding,
  5. double? minimumWidth,
  6. Color? backgroundColor,
})

This function is intentionally doing things using the low-level primitives to avoid depending on any subsystems that may have ended up in an unstable state -- after all, this class is mainly used when things have gone wrong.

Implementation

static Widget errorDisplayWidget(
  FlutterErrorDetails details, {
  i.ParagraphStyle? paragraphStyle,
  i.TextStyle? textStyle,
  EdgeInsets? padding,
  double? minimumWidth,
  Color? backgroundColor,
}) {
  String message;
  try {
    message = 'ERROR\n\n${details.exception}\n\n';

    final stackTrace = details.stack.toString().split('\n');

    final length = stackTrace.length > 5 ? 5 : stackTrace.length;

    final buffer = StringBuffer()..write(message);
    for (var i = 0; i < length; i++) {
      buffer.write('${stackTrace[i]}\n');
    }
    message = buffer.toString();
  } catch (e) {
    message = 'Error';
  }
  return _ErrorRenderObjectWidget(
    message: message,
    error: details.exception,
    paragraphStyle: paragraphStyle,
    textStyle: textStyle,
    padding: padding,
    minimumWidth: minimumWidth,
    backgroundColor: backgroundColor,
  );
}