dumpErrorToConsole method Null safety

void dumpErrorToConsole(
  1. FlutterErrorDetails details,
  2. {bool forceReport = false}
)

Prints the given exception details to the console.

The first time this is called, it dumps a very verbose message to the console using debugPrint.

Subsequent calls only dump the first line of the exception, unless forceReport is set to true (in which case it dumps the verbose message).

Call resetErrorCount to cause this method to go back to acting as if it had not been called before (so the next message is verbose again).

The default behavior for the onError handler is to call this function.

Implementation

static void dumpErrorToConsole(FlutterErrorDetails details, { bool forceReport = false }) {
  assert(details != null);
  assert(details.exception != null);
  bool isInDebugMode = false;
  assert(() {
    // In debug mode, we ignore the "silent" flag.
    isInDebugMode = true;
    return true;
  }());
  final bool reportError = isInDebugMode || details.silent != true; // could be null
  if (!reportError && !forceReport)
    return;
  if (_errorCount == 0 || forceReport) {
    // Diagnostics is only available in debug mode. In profile and release modes fallback to plain print.
    if (isInDebugMode) {
      debugPrint(
        TextTreeRenderer(
          wrapWidthProperties: wrapWidth,
          maxDescendentsTruncatableNode: 5,
        ).render(details.toDiagnosticsNode(style: DiagnosticsTreeStyle.error)).trimRight(),
      );
    } else {
      debugPrintStack(
        stackTrace: details.stack,
        label: details.exception.toString(),
        maxFrames: 100,
      );
    }
  } else {
    debugPrint('Another exception was thrown: ${details.summary}');
  }
  _errorCount += 1;
}