dumpErrorToConsole method

void dumpErrorToConsole (FlutterErrorDetails details, { 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 reportError = details.silent != true; // could be null
  assert(() {
    // In checked mode, we ignore the "silent" flag.
    reportError = true;
    return true;
  }());
  if (!reportError && !forceReport)
    return;
  if (_errorCount == 0 || forceReport) {
    debugPrint(
      TextTreeRenderer(
        wrapWidth: wrapWidth,
        wrapWidthProperties: wrapWidth,
        maxDescendentsTruncatableNode: 5,
      ).render(details.toDiagnosticsNode(style: DiagnosticsTreeStyle.error)).trimRight()
    );
  } else {
    debugPrint('Another exception was thrown: ${details.summary}');
  }
  _errorCount += 1;
}