errorDisplayWidget static method

Widget errorDisplayWidget(
  1. FlutterErrorDetails details
)

This class 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) {
  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';
  }

  final exception = details.exception;
  return DisplayErrorWidget(
      message: message, error: exception is Error ? exception : null);
}