parseStackLine method

Map<String, dynamic> parseStackLine(
  1. String stackLine
)

Parses a single line from a stack trace for method, file, line, and column info.

Implementation

Map<String, dynamic> parseStackLine(String stackLine) {
  final regex = RegExp(r'#\d+\s+(.*?)\s+\((.*?):(\d+):(\d+)\)');
  final match = regex.firstMatch(stackLine);

  if (match != null) {
    return {
      'methodName': match.group(1) ?? 'Unknown method',
      'file': match.group(2) ?? 'Unknown file',
      'line': int.tryParse(match.group(3) ?? '0') ?? 0,
      'column': int.tryParse(match.group(4) ?? '0') ?? 0,
    };
  }

  return {
    'methodName': 'Unknown method',
    'file': 'Unknown file',
    'line': 0,
    'column': 0,
  };
}