formatStackTrace method

String? formatStackTrace(
  1. StackTrace? stackTrace,
  2. int? methodCount
)

Implementation

String? formatStackTrace(StackTrace? stackTrace, int? methodCount) {
  List<String> lines = stackTrace
      .toString()
      .split('\n')
      .where(
        (line) =>
            !_discardDeviceStacktraceLine(line) &&
            !_discardWebStacktraceLine(line) &&
            !_discardBrowserStacktraceLine(line) &&
            line.isNotEmpty,
      )
      .toList();
  List<String> formatted = [];

  int stackTraceLength =
      (methodCount != null ? min(lines.length, methodCount) : lines.length);
  for (int count = 0; count < stackTraceLength; count++) {
    var line = lines[count];
    if (count < stackTraceBeginIndex) {
      continue;
    }
    formatted.add('#$count   ${line.replaceFirst(RegExp(r'#\d+\s+'), '')}');
  }

  if (formatted.isEmpty) {
    return null;
  } else {
    return formatted.join('\n');
  }
}