getStackTraceElements function
Implementation
List<Map<String, String>> getStackTraceElements(StackTrace stackTrace) {
final Trace trace = Trace.parseVM(stackTrace.toString()).terse;
final List<Map<String, String>> elements = <Map<String, String>>[];
for (final Frame frame in trace.frames) {
final Map<String, String> element = <String, String>{
'file': frame.library,
'line': frame.line?.toString() ?? '0',
};
final String member = frame.member ?? '<fn>';
final List<String> members = member.split('.');
if (members.length > 1) {
element['method'] = members.sublist(1).join('.');
element['class'] = members.first;
} else {
element['method'] = member;
}
elements.add(element);
}
return elements;
}